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

Make miracle-wifid conexists with other network tools

The new option --lazy-managed will let miracle-wifid don't managed the
links automatically. Instead, the link will be managed only when the new
DBus property Managed was set to true. So this will be possible that
miracle-wifid could be conexists with other network tools like
networkmanager.

For example, unmange the device in networkmanager with setting the DBus
property org.freedesktop.NetworkManager.Device.Managed to false and
manage it in miracle-wifid with setting
org.freedesktop.miracle.wifi.Link.Managed to true, then both them could
works and don't need to kill each other.

Besides, there is new command named make-managed in miracle-wifictl and
miracle-sinkctla.
This commit is contained in:
Xu Fasheng 2016-10-21 00:43:03 +08:00 committed by Derek Dai
parent d239c528ff
commit 7d7df75bc9
No known key found for this signature in database
GPG key ID: E109CC97553EF009
9 changed files with 260 additions and 26 deletions

View file

@ -415,6 +415,8 @@ static int ctl_link_parse_properties(struct ctl_link *l,
bool p2p_scanning_set = false;
char *tmp;
int p2p_scanning, r;
bool managed_set = false;
int managed;
if (!l || !m)
return cli_EINVAL();
@ -445,6 +447,13 @@ static int ctl_link_parse_properties(struct ctl_link *l,
&friendly_name);
if (r < 0)
return cli_log_parser(r);
} else if (!strcmp(t, "Managed")) {
r = bus_message_read_basic_variant(m, "b",
&managed);
if (r < 0)
return cli_log_parser(r);
managed_set = true;
} else if (!strcmp(t, "P2PScanning")) {
r = bus_message_read_basic_variant(m, "b",
&p2p_scanning);
@ -495,6 +504,9 @@ static int ctl_link_parse_properties(struct ctl_link *l,
}
}
if (managed_set)
l->managed = managed;
if (p2p_scanning_set)
l->p2p_scanning = p2p_scanning;
@ -621,6 +633,63 @@ int ctl_link_set_wfd_subelements(struct ctl_link *l, const char *val)
return 0;
}
int ctl_link_set_managed(struct ctl_link *l, bool val)
{
_sd_bus_message_unref_ sd_bus_message *m = NULL;
_sd_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL;
_shl_free_ char *node = NULL;
int r;
if (!l)
return cli_EINVAL();
if (l->managed == val)
return 0;
r = sd_bus_path_encode("/org/freedesktop/miracle/wifi/link",
l->label,
&node);
if (r < 0)
return cli_ERR(r);
r = sd_bus_message_new_method_call(l->w->bus,
&m,
"org.freedesktop.miracle.wifi",
node,
"org.freedesktop.DBus.Properties",
"Set");
if (r < 0)
return cli_log_create(r);
r = sd_bus_message_append(m, "ss",
"org.freedesktop.miracle.wifi.Link",
"Managed");
if (r < 0)
return cli_log_create(r);
r = sd_bus_message_open_container(m, 'v', "b");
if (r < 0)
return cli_log_create(r);
r = sd_bus_message_append(m, "b", val);
if (r < 0)
return cli_log_create(r);
r = sd_bus_message_close_container(m);
if (r < 0)
return cli_log_create(r);
r = sd_bus_call(l->w->bus, m, 0, &err, NULL);
if (r < 0) {
cli_error("cannot change managed state on link %s to %d: %s",
l->label, val, bus_error_message(&err, r));
return r;
}
l->managed = val;
return 0;
}
int ctl_link_set_p2p_scanning(struct ctl_link *l, bool val)
{
_sd_bus_message_unref_ sd_bus_message *m = NULL;

View file

@ -71,6 +71,7 @@ struct ctl_link {
unsigned int ifindex;
char *ifname;
char *friendly_name;
bool managed;
char *wfd_subelements;
bool p2p_scanning;
};
@ -78,6 +79,7 @@ struct ctl_link {
#define link_from_dlist(_l) shl_dlist_entry((_l), struct ctl_link, list);
int ctl_link_set_friendly_name(struct ctl_link *l, const char *name);
int ctl_link_set_managed(struct ctl_link *l, bool val);
int ctl_link_set_wfd_subelements(struct ctl_link *l, const char *val);
int ctl_link_set_p2p_scanning(struct ctl_link *l, bool val);

View file

@ -81,19 +81,20 @@ static int cmd_list(char **args, unsigned int n)
/* list links */
cli_printf("%6s %-24s %-30s\n",
"LINK", "INTERFACE", "FRIENDLY-NAME");
cli_printf("%6s %-24s %-30s %-10s\n",
"LINK", "INTERFACE", "FRIENDLY-NAME", "MANAGED");
shl_dlist_for_each(i, &wifi->links) {
l = link_from_dlist(i);
++link_cnt;
cli_printf("%6s %-24s %-30s\n",
cli_printf("%6s %-24s %-30s %-10s\n",
l->label,
shl_isempty(l->ifname) ?
"<unknown>" : l->ifname,
shl_isempty(l->friendly_name) ?
"<unknown>" : l->friendly_name);
"<unknown>" : l->friendly_name,
l->managed ? "yes": "no");
}
cli_printf("\n");
@ -154,6 +155,7 @@ static int cmd_show(char **args, unsigned int n)
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
if (l->wfd_subelements && *l->wfd_subelements)
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
cli_printf("Managed=%d\n", l->managed);
} else if (p) {
cli_printf("Peer=%s\n", p->label);
if (p->p2p_mac && *p->p2p_mac)
@ -207,6 +209,9 @@ static int cmd_run(char **args, unsigned int n)
return 0;
}
if (!l->managed)
return log_EUNMANAGED();
run_on(l);
return 0;
@ -237,11 +242,35 @@ static int cmd_bind(char **args, unsigned int n)
if (!l)
return 0;
if (!l->managed)
return log_EUNMANAGED();
run_on(l);
return 0;
}
/*
* cmd: set-managed
*/
static int cmd_set_managed(char **args, unsigned int n)
{
struct ctl_link *l = NULL;
bool managed = true;
l = ctl_wifi_search_link(wifi, args[0]);
if (!l) {
cli_error("unknown link %s", args[0]);
return 0;
}
if (!strcmp(args[1], "no")) {
managed = false;
}
return ctl_link_set_managed(l, managed);
}
/*
* cmd: quit/exit
*/
@ -338,6 +367,7 @@ static const struct cli_cmd cli_cmds[] = {
{ "show", "<link|peer>", CLI_M, CLI_LESS, 1, cmd_show, "Show detailed object information" },
{ "run", "<link>", CLI_M, CLI_EQUAL, 1, cmd_run, "Run sink on given link" },
{ "bind", "<link>", CLI_M, CLI_EQUAL, 1, cmd_bind, "Like 'run' but bind the link name to run when it is hotplugged" },
{ "set-managed", "<link> <yes|no>", CLI_M, CLI_EQUAL, 2, cmd_set_managed, "Manage or unmnage a link" },
{ "quit", NULL, CLI_Y, CLI_MORE, 0, cmd_quit, "Quit program" },
{ "exit", NULL, CLI_Y, CLI_MORE, 0, cmd_quit, NULL },
{ "help", NULL, CLI_M, CLI_MORE, 0, NULL, "Print help" },

View file

@ -51,19 +51,20 @@ static int cmd_list(char **args, unsigned int n)
/* list links */
cli_printf("%6s %-24s %-30s\n",
"LINK", "INTERFACE", "FRIENDLY-NAME");
cli_printf("%6s %-24s %-30s %-10s\n",
"LINK", "INTERFACE", "FRIENDLY-NAME", "MANAGED");
shl_dlist_for_each(i, &wifi->links) {
l = link_from_dlist(i);
++link_cnt;
cli_printf("%6s %-24s %-30s\n",
cli_printf("%6s %-24s %-30s %-10s\n",
l->label,
shl_isempty(l->ifname) ?
"<unknown>" : l->ifname,
shl_isempty(l->friendly_name) ?
"<unknown>" : l->friendly_name);
"<unknown>" : l->friendly_name,
l->managed ? "yes": "no");
}
cli_printf("\n");
@ -156,6 +157,7 @@ static int cmd_show(char **args, unsigned int n)
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
if (l->wfd_subelements && *l->wfd_subelements)
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
cli_printf("Managed=%d\n", l->managed);
} else if (p) {
cli_printf("Peer=%s\n", p->label);
if (p->p2p_mac && *p->p2p_mac)
@ -211,9 +213,51 @@ static int cmd_set_friendly_name(char **args, unsigned int n)
return 0;
}
if (!l->managed)
return log_EUNMANAGED();
return ctl_link_set_friendly_name(l, name);
}
/*
* cmd: set-managed
*/
static int cmd_set_managed(char **args, unsigned int n)
{
struct ctl_link *l = NULL;
const char *value;
bool managed = true;
if (n < 1) {
cli_printf("To what?\n");
return 0;
}
if (n > 1) {
l = ctl_wifi_search_link(wifi, args[0]);
if (!l) {
cli_error("unknown link %s", args[0]);
return 0;
}
value = args[1];
} else {
value = args[0];
}
l = l ? : selected_link;
if (!l) {
cli_error("no link selected");
return 0;
}
if (!strcmp(value, "no")) {
managed = false;
}
return ctl_link_set_managed(l, managed);
}
/*
* cmd: p2p-scan
*/
@ -242,6 +286,9 @@ static int cmd_p2p_scan(char **args, unsigned int n)
return 0;
}
if (!l->managed)
return log_EUNMANAGED();
return ctl_link_set_p2p_scanning(l, !stop);
}
@ -289,6 +336,9 @@ static int cmd_connect(char **args, unsigned int n)
pin = "";
}
if (!p->l->managed)
return log_EUNMANAGED();
return ctl_peer_connect(p, prov, pin);
}
@ -311,6 +361,9 @@ static int cmd_disconnect(char **args, unsigned int n)
return 0;
}
if (!p->l->managed)
return log_EUNMANAGED();
return ctl_peer_disconnect(p);
}
@ -333,6 +386,7 @@ static const struct cli_cmd cli_cmds[] = {
{ "select", "[link]", CLI_Y, CLI_LESS, 1, cmd_select, "Select default link" },
{ "show", "[link|peer]", CLI_M, CLI_LESS, 1, cmd_show, "Show detailed object information" },
{ "set-friendly-name", "[link] <name>", CLI_M, CLI_LESS, 2, cmd_set_friendly_name, "Set friendly name of an object" },
{ "set-managed", "[link] <yes|no>", CLI_M, CLI_LESS, 2, cmd_set_managed, "Manage or unmnage a link" },
{ "p2p-scan", "[link] [stop]", CLI_Y, CLI_LESS, 2, cmd_p2p_scan, "Control neighborhood P2P scanning" },
{ "connect", "<peer> [provision] [pin]", CLI_M, CLI_LESS, 3, cmd_connect, "Connect to peer" },
{ "disconnect", "<peer>", CLI_M, CLI_EQUAL, 1, cmd_disconnect, "Disconnect from peer" },