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")
OPTION(BUILD_ENABLE_DEBUG "Enable Debug" ON )
OPTION(RELY_UDEV "Rely in udev tag to select device" OFF )
OPTION(BUILD_TESTS "Enable TEST" ON )
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):
Autotools:
$ ./autogen.sh
@ -56,6 +55,14 @@ 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
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 \
-I $(top_srcdir)/src \
-I $(top_srcdir)/src/shared \
-DBUILD_ENABLE_DEBUG \
'-DBUILD_BINDIR="$(bindir)"'
AM_LDFLAGS = -Wl,--as-needed \

View file

@ -36,6 +36,10 @@ AC_PROG_AWK
LT_PREREQ(2.2)
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
#

View file

@ -1,7 +1,5 @@
#!/bin/bash
./kill-wpa.sh
. miracle-utils.sh
ETHER_NAMES=$(find_choosable_networknames)
@ -17,7 +15,7 @@ then
ETHERNAME="$ETHER_NAMES"
elif [ 2 -le $ETHER_COUNT ]
then
echo choose device for normal connection:
echo choose device to use with miraclecast:
QUIT="exit"
select et_name in $ETHER_NAMES $QUIT
do
@ -42,11 +40,16 @@ then
done
fi
# default path for config file
CONFIG_FILE=${1:-/run/network/wpa_supplicant_${ETHERNAME}.conf}
read -p "Provide order to udev rule (default 10): " -e -i 10 ORDER
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)"
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
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] = {
[LOG_TRACE] = "TRACE",
[LOG_DEBUG] = "DEBUG",
[LOG_INFO] = "INFO",
[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_group *g;
const char *mac, *ifname, *go;
const char *mac, *ssid, *ifname, *go;
bool is_go;
int r;
@ -1210,6 +1210,11 @@ static void supplicant_event_p2p_group_started(struct supplicant *s,
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);
if (r < 0) {
log_debug("no ifname in P2P-GROUP-STARTED: %s",

View file

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