mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-13 06:21:54 +00:00
miracle-wifid: change managed property of link by method call instead of
set property due to wpa_supplicant needs time to get ready
This commit is contained in:
parent
3558c4e511
commit
0677d64252
5 changed files with 89 additions and 59 deletions
|
@ -126,10 +126,11 @@ nm_manage()
|
|||
|
||||
link_unmanage()
|
||||
{
|
||||
set_prop org.freedesktop.miracle.wifi \
|
||||
invoke org.freedesktop.miracle.wifi \
|
||||
/org/freedesktop/miracle/wifi/link/$link_index \
|
||||
org.freedesktop.miracle.wifi.Link \
|
||||
Managed b false
|
||||
Managed false \
|
||||
Unmanage
|
||||
}
|
||||
|
||||
link_stop_p2pscan()
|
||||
|
@ -161,10 +162,11 @@ set_prop org.freedesktop.NetworkManager \
|
|||
org.freedesktop.NetworkManager.Device \
|
||||
Managed b false
|
||||
cleanup_push nm_manage
|
||||
set_prop org.freedesktop.miracle.wifi \
|
||||
invoke org.freedesktop.miracle.wifi \
|
||||
/org/freedesktop/miracle/wifi/link/$link_index \
|
||||
org.freedesktop.miracle.wifi.Link \
|
||||
Managed b true
|
||||
Managed true \
|
||||
Manage
|
||||
cleanup_push link_unmanage
|
||||
set_prop org.freedesktop.miracle.wifi \
|
||||
/org/freedesktop/miracle/wifi/link/$link_index \
|
||||
|
|
|
@ -606,22 +606,28 @@ static int link_dbus_get_managed(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int link_dbus_set_managed(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *value,
|
||||
void *data,
|
||||
sd_bus_error *err)
|
||||
static int link_dbus_manage(sd_bus_message *msg,
|
||||
void *data,
|
||||
sd_bus_error *err)
|
||||
{
|
||||
struct link *l = data;
|
||||
int val, r;
|
||||
|
||||
r = sd_bus_message_read(value, "b", &val);
|
||||
if (r < 0)
|
||||
int r = link_set_managed(l, true);
|
||||
if(r < 0)
|
||||
return r;
|
||||
|
||||
return link_set_managed(l, val);
|
||||
return sd_bus_reply_method_return(msg, NULL);
|
||||
}
|
||||
|
||||
static int link_dbus_unmanage(sd_bus_message *msg,
|
||||
void *data,
|
||||
sd_bus_error *err)
|
||||
{
|
||||
struct link *l = data;
|
||||
int r = link_set_managed(l, false);
|
||||
if(r < 0)
|
||||
return r;
|
||||
|
||||
return sd_bus_reply_method_return(msg, NULL);
|
||||
}
|
||||
|
||||
static int link_dbus_get_p2p_scanning(sd_bus *bus,
|
||||
|
@ -699,6 +705,16 @@ static int link_dbus_set_wfd_subelements(sd_bus *bus,
|
|||
|
||||
static const sd_bus_vtable link_dbus_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_METHOD("Manage",
|
||||
NULL,
|
||||
NULL,
|
||||
link_dbus_manage,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Unmanage",
|
||||
NULL,
|
||||
NULL,
|
||||
link_dbus_unmanage,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_PROPERTY("InterfaceIndex",
|
||||
"u",
|
||||
link_dbus_get_interface_index,
|
||||
|
@ -720,12 +736,11 @@ static const sd_bus_vtable link_dbus_vtable[] = {
|
|||
link_dbus_set_friendly_name,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE | SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_WRITABLE_PROPERTY("Managed",
|
||||
SD_BUS_PROPERTY("Managed",
|
||||
"b",
|
||||
link_dbus_get_managed,
|
||||
link_dbus_set_managed,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE | SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("P2PScanning",
|
||||
"b",
|
||||
link_dbus_get_p2p_scanning,
|
||||
|
|
|
@ -170,22 +170,30 @@ int link_set_managed(struct link *l, bool set)
|
|||
return 0;
|
||||
|
||||
if (set) {
|
||||
log_info("manage link %s", l->ifname);
|
||||
|
||||
r = supplicant_start(l->s);
|
||||
if (r < 0) {
|
||||
log_error("cannot start supplicant on %s", l->ifname);
|
||||
return -EFAULT;
|
||||
}
|
||||
log_info("acquiring link ownership %s", l->ifname);
|
||||
} else {
|
||||
log_info("link %s no longer managed", l->ifname);
|
||||
log_info("droping link ownership %s", l->ifname);
|
||||
supplicant_stop(l->s);
|
||||
}
|
||||
|
||||
l->managed = set;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void link_supplicant_managed(struct link *l)
|
||||
{
|
||||
if(l->managed) {
|
||||
return;
|
||||
}
|
||||
|
||||
l->managed = true;
|
||||
link_dbus_properties_changed(l, "Managed", NULL);
|
||||
}
|
||||
|
||||
int link_renamed(struct link *l, const char *ifname)
|
||||
{
|
||||
char *t;
|
||||
|
@ -338,6 +346,9 @@ void link_supplicant_stopped(struct link *l)
|
|||
if (!l || !l->public)
|
||||
return;
|
||||
|
||||
l->managed = false;
|
||||
link_dbus_properties_changed(l, "Managed", NULL);
|
||||
|
||||
log_info("link %s unmanaged", l->ifname);
|
||||
}
|
||||
|
||||
|
|
|
@ -2419,45 +2419,45 @@ static void supplicant_run(struct supplicant *s, const char *binary)
|
|||
|
||||
static int supplicant_find(char **binary)
|
||||
{
|
||||
_shl_free_ char *path = getenv("PATH");
|
||||
if(!path) {
|
||||
return -EINVAL;
|
||||
}
|
||||
_shl_free_ char *path = getenv("PATH");
|
||||
if(!path) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
path = strdup(path);
|
||||
if(!path) {
|
||||
return log_ENOMEM();
|
||||
}
|
||||
path = strdup(path);
|
||||
if(!path) {
|
||||
return log_ENOMEM();
|
||||
}
|
||||
|
||||
struct stat bin_stat;
|
||||
char *curr = path, *next;
|
||||
while(1) {
|
||||
curr = strtok_r(curr, ":", &next);
|
||||
if(!curr) {
|
||||
break;
|
||||
}
|
||||
struct stat bin_stat;
|
||||
char *curr = path, *next;
|
||||
while(1) {
|
||||
curr = strtok_r(curr, ":", &next);
|
||||
if(!curr) {
|
||||
break;
|
||||
}
|
||||
|
||||
_shl_free_ char *bin = shl_strcat(curr, "/wpa_supplicant");
|
||||
if (!bin)
|
||||
return log_ENOMEM();
|
||||
_shl_free_ char *bin = shl_strcat(curr, "/wpa_supplicant");
|
||||
if (!bin)
|
||||
return log_ENOMEM();
|
||||
|
||||
if(stat(bin, &bin_stat) < 0) {
|
||||
if(ENOENT == errno || ENOTDIR == errno) {
|
||||
goto end;
|
||||
}
|
||||
return log_ERRNO();
|
||||
}
|
||||
if(stat(bin, &bin_stat) < 0) {
|
||||
if(ENOENT == errno || ENOTDIR == errno) {
|
||||
goto end;
|
||||
}
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
if (!access(bin, X_OK)) {
|
||||
*binary = strdup(bin);
|
||||
return 0;
|
||||
}
|
||||
if (!access(bin, X_OK)) {
|
||||
*binary = strdup(bin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
end:
|
||||
curr = NULL;
|
||||
}
|
||||
curr = NULL;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int supplicant_spawn(struct supplicant *s)
|
||||
|
@ -2473,12 +2473,12 @@ static int supplicant_spawn(struct supplicant *s)
|
|||
|
||||
log_debug("spawn supplicant of %s", s->l->ifname);
|
||||
|
||||
if (supplicant_find(&binary) < 0) {
|
||||
log_error("execution of wpas (%s) not possible: %m", binary);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (supplicant_find(&binary) < 0) {
|
||||
log_error("execution of wpas (%s) not possible: %m", binary);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
log_info("wpa_supplicant found: %s", binary);
|
||||
log_info("wpa_supplicant found: %s", binary);
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
|
@ -2561,6 +2561,7 @@ static int supplicant_timer_fn(sd_event_source *source,
|
|||
} else {
|
||||
/* wpas is running smoothly, disable timer */
|
||||
sd_event_source_set_enabled(source, SD_EVENT_OFF);
|
||||
link_supplicant_managed(s->l);
|
||||
}
|
||||
} else {
|
||||
/* Who armed this timer? What timer is this? */
|
||||
|
|
|
@ -172,6 +172,7 @@ int link_set_p2p_scanning(struct link *l, bool set);
|
|||
bool link_get_p2p_scanning(struct link *l);
|
||||
const char *link_get_mac_addr(struct link *l);
|
||||
|
||||
void link_supplicant_managed(struct link *l);
|
||||
void link_supplicant_started(struct link *l);
|
||||
void link_supplicant_stopped(struct link *l);
|
||||
void link_supplicant_p2p_scan_changed(struct link *l, bool new_value);
|
||||
|
|
Loading…
Reference in a new issue