1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-03-09 23:38:56 +00:00

Select interface to use

Start miraclecast against interface of choose.

- By tagged udev device
- By `--interface` or `-i` option

resolves #36, resolves #43, resolves #46
This commit is contained in:
albfan 2015-08-23 13:24:48 +02:00
parent 6cc5876ba6
commit 73adee82bf
8 changed files with 63 additions and 25 deletions

View file

@ -13,6 +13,7 @@ add_subdirectory(test)
SET(BUILD_BINDIR "${CMAKE_INSTALL_PREFIX}/bin") SET(BUILD_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
OPTION(BUILD_ENABLE_DEBUG "Enable Debug" ON ) OPTION(BUILD_ENABLE_DEBUG "Enable Debug" ON )
OPTION(RELY_UDEV "Rely in udev tag to select device" OFF )
OPTION(BUILD_TESTS "Enable TEST" ON ) OPTION(BUILD_TESTS "Enable TEST" ON )
SET(PACKAGE_NAME miraclecast) SET(PACKAGE_NAME miraclecast)

View file

@ -30,7 +30,6 @@ The MiracleCast projects requires the following software to be installed:
To compile MiracleCast, you can choose from [autotools](http://en.wikipedia.org/wiki/GNU_build_system) or [cmake](http://en.wikipedia.org/wiki/CMake): To compile MiracleCast, you can choose from [autotools](http://en.wikipedia.org/wiki/GNU_build_system) or [cmake](http://en.wikipedia.org/wiki/CMake):
Autotools: Autotools:
$ ./autogen.sh $ ./autogen.sh
@ -56,6 +55,14 @@ Install
$ sudo make install $ sudo make install
## Automatic interface selection with udev
If you want to select the interface to start miraclecast with, add a udev rule with the script [res/write-udev-rule.sh](https://github.com/albfan/miraclecast/blob/master/res/write-udev-rule.sh) and configure miraclecast with
$ ../configure --enable-rely-udev
You can also choose the interface with `--interface` option for miracle-wifid.
### Ubuntu ### Ubuntu
This specific linux flavour is so hard to get miraclecast dependencies that an alternative repo was created to install systemd with dbus This specific linux flavour is so hard to get miraclecast dependencies that an alternative repo was created to install systemd with dbus

View file

@ -11,7 +11,6 @@ AM_CFLAGS = -Wall \
AM_CPPFLAGS = -include $(top_builddir)/config.h \ AM_CPPFLAGS = -include $(top_builddir)/config.h \
-I $(top_srcdir)/src \ -I $(top_srcdir)/src \
-I $(top_srcdir)/src/shared \ -I $(top_srcdir)/src/shared \
-DBUILD_ENABLE_DEBUG \
'-DBUILD_BINDIR="$(bindir)"' '-DBUILD_BINDIR="$(bindir)"'
AM_LDFLAGS = -Wl,--as-needed \ AM_LDFLAGS = -Wl,--as-needed \

View file

@ -36,6 +36,10 @@ AC_PROG_AWK
LT_PREREQ(2.2) LT_PREREQ(2.2)
LT_INIT LT_INIT
AC_ARG_ENABLE([rely-udev],
AS_HELP_STRING([--enable-rely-udev], [Use tagged device with miraclecast]), AC_DEFINE([RELY_UDEV], [], [Rely on udev to find miraclecast device]))
AC_ARG_ENABLE([log-debug],
AS_HELP_STRING([--disable-log-debug], [Disable log debug]), , AC_DEFINE([BUILD_ENABLE_DEBUG], [], [Enable debug log level]))
# #
# Mandatory dependencies # Mandatory dependencies
# #

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
./kill-wpa.sh
. miracle-utils.sh . miracle-utils.sh
ETHER_NAMES=$(find_choosable_networknames) ETHER_NAMES=$(find_choosable_networknames)
@ -17,7 +15,7 @@ then
ETHERNAME="$ETHER_NAMES" ETHERNAME="$ETHER_NAMES"
elif [ 2 -le $ETHER_COUNT ] elif [ 2 -le $ETHER_COUNT ]
then then
echo choose device for normal connection: echo choose device to use with miraclecast:
QUIT="exit" QUIT="exit"
select et_name in $ETHER_NAMES $QUIT select et_name in $ETHER_NAMES $QUIT
do do
@ -42,11 +40,16 @@ then
done done
fi fi
# default path for config file read -p "Provide order to udev rule (default 10): " -e -i 10 ORDER
CONFIG_FILE=${1:-/run/network/wpa_supplicant_${ETHERNAME}.conf}
NUMBER=10 RULE_FILE="/etc/udev/rules.d/${ORDER}-network.rules"
cat > /etc/udev/rules.d/${NUMBER}-network.rules << EOF echo "...Press enter to finish (sorry, don't know why. It is related with sudo tee)"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="$(cat /sys/class/net/${ETHERNAME}/address)", NAME="${ETHERNAME}", TAGS+="miracle"
cat | sudo tee "${RULE_FILE}" &>/dev/null <<-EOF
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="$(cat /sys/class/net/${ETHERNAME}/address)", NAME="${ETHERNAME}", TAGS+="miracle"
EOF EOF
echo file "${RULE_FILE}" writed
cat "${RULE_FILE}"

View file

@ -112,6 +112,7 @@ static void log__submit(const char *file,
*/ */
static const char *log__sev2str[LOG_SEV_NUM] = { static const char *log__sev2str[LOG_SEV_NUM] = {
[LOG_TRACE] = "TRACE",
[LOG_DEBUG] = "DEBUG", [LOG_DEBUG] = "DEBUG",
[LOG_INFO] = "INFO", [LOG_INFO] = "INFO",
[LOG_NOTICE] = "NOTICE", [LOG_NOTICE] = "NOTICE",

View file

@ -1199,7 +1199,7 @@ static void supplicant_event_p2p_group_started(struct supplicant *s,
{ {
struct supplicant_peer *sp; struct supplicant_peer *sp;
struct supplicant_group *g; struct supplicant_group *g;
const char *mac, *ifname, *go; const char *mac, *ssid, *ifname, *go;
bool is_go; bool is_go;
int r; int r;
@ -1210,6 +1210,11 @@ static void supplicant_event_p2p_group_started(struct supplicant *s,
return; return;
} }
r = wpas_message_dict_read(ev, "ssid", 's', &ssid);
if (r == 0) {
log_debug("ssid: %s", ssid);
}
r = wpas_message_argv_read(ev, 0, 's', &ifname); r = wpas_message_argv_read(ev, 0, 's', &ifname);
if (r < 0) { if (r < 0) {
log_debug("no ifname in P2P-GROUP-STARTED: %s", log_debug("no ifname in P2P-GROUP-STARTED: %s",

View file

@ -40,9 +40,8 @@
#include "wifid.h" #include "wifid.h"
#include "config.h" #include "config.h"
#define RELY_UDEV 0
const char *arg_wpa_bindir = "/usr/bin"; const char *arg_wpa_bindir = "/usr/bin";
const char *interface_name = NULL;
unsigned int arg_wpa_loglevel = LOG_NOTICE; unsigned int arg_wpa_loglevel = LOG_NOTICE;
/* /*
@ -90,6 +89,10 @@ static void manager_add_udev_link(struct manager *m,
if (!ifname) if (!ifname)
return; return;
if (interface_name && strcmp(interface_name, ifname)) {
return;
}
/* ignore dynamic p2p interfaces */ /* ignore dynamic p2p interfaces */
if (shl_startswith(ifname, "p2p-")) if (shl_startswith(ifname, "p2p-"))
return; return;
@ -100,10 +103,15 @@ static void manager_add_udev_link(struct manager *m,
link_set_friendly_name(l, m->friendly_name); link_set_friendly_name(l, m->friendly_name);
#if RELY_UDEV #ifdef RELY_UDEV
if (udev_device_has_tag(d, "miracle")) if (udev_device_has_tag(d, "miracle")) {
#else
if (!interface_name || !strcmp(interface_name, ifname)) {
#endif #endif
link_set_managed(l, true); link_set_managed(l, true);
} else {
log_debug("ignored device: %s", ifname);
}
} }
static int manager_udev_fn(sd_event_source *source, static int manager_udev_fn(sd_event_source *source,
@ -132,19 +140,23 @@ static int manager_udev_fn(sd_event_source *source,
if (l) if (l)
link_free(l); link_free(l);
} else if (l) { } else if (l) {
ifname = udev_device_get_property_value(d, "INTERFACE");
if (action && !strcmp(action, "move")) { if (action && !strcmp(action, "move")) {
ifname = udev_device_get_property_value(d, "INTERFACE");
if (ifname) if (ifname)
link_renamed(l, ifname); link_renamed(l, ifname);
} }
#if RELY_UDEV #ifdef RELY_UDEV
if (udev_device_has_tag(d, "miracle")) if (udev_device_has_tag(d, "miracle"))
link_set_managed(l, true); link_set_managed(l, true);
else else
link_set_managed(l, false); link_set_managed(l, false);
#else #else
link_set_managed(l, true); if (!interface_name || !strcmp(interface_name, ifname)) {
link_set_managed(l, true);
} else {
log_debug("ignored device: %s", ifname);
}
#endif #endif
} else { } else {
manager_add_udev_link(m, d); manager_add_udev_link(m, d);
@ -438,13 +450,15 @@ static int help(void)
*/ */
printf("%s [OPTIONS...] ...\n\n" printf("%s [OPTIONS...] ...\n\n"
"Wifi Management Daemon.\n\n" "Wifi Management Daemon.\n\n"
" -h --help Show this help\n" " -h --help Show this help\n"
" --version Show package version\n" " --version Show package version\n"
" --log-level <lvl> Maximum level for log messages\n" " --log-level <lvl> Maximum level for log messages\n"
" --log-time Prefix log-messages with timestamp\n" " --log-time Prefix log-messages with timestamp\n"
"\n" "\n"
" --wpa-bindir <dir> wpa_supplicant binary dir [/usr/bin]\n" " -i --interface Choose the interface to use\n"
" --wpa-loglevel <lvl> wpa_supplicant log-level\n" "\n"
" --wpa-bindir <dir> wpa_supplicant binary dir [/usr/bin]\n"
" --wpa-loglevel <lvl wpa_supplicant log-level\n"
, program_invocation_short_name); , program_invocation_short_name);
/* /*
* 80-char barrier: * 80-char barrier:
@ -472,14 +486,18 @@ static int parse_argv(int argc, char *argv[])
{ "wpa-bindir", required_argument, NULL, ARG_WPA_BINDIR }, { "wpa-bindir", required_argument, NULL, ARG_WPA_BINDIR },
{ "wpa-loglevel", required_argument, NULL, ARG_WPA_LOGLEVEL }, { "wpa-loglevel", required_argument, NULL, ARG_WPA_LOGLEVEL },
{ "interface", required_argument, NULL, 'i' },
{} {}
}; };
int c; int c;
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) { while ((c = getopt_long(argc, argv, "hi:", options, NULL)) >= 0) {
switch (c) { switch (c) {
case 'h': case 'h':
return help(); return help();
case 'i':
interface_name = optarg;
break;
case ARG_VERSION: case ARG_VERSION:
puts(PACKAGE_STRING); puts(PACKAGE_STRING);
return 0; return 0;