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 coexists with other network tools like networkmanager. For example, unmanage 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-sinkctl. closes #135, #75
This commit is contained in:
parent
ec7e11c8bf
commit
8b76e3c212
9 changed files with 272 additions and 25 deletions
|
@ -414,6 +414,8 @@ static int ctl_link_parse_properties(struct ctl_link *l,
|
||||||
bool p2p_scanning_set = false;
|
bool p2p_scanning_set = false;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int p2p_scanning, r;
|
int p2p_scanning, r;
|
||||||
|
bool managed_set = false;
|
||||||
|
int managed;
|
||||||
|
|
||||||
if (!l || !m)
|
if (!l || !m)
|
||||||
return cli_EINVAL();
|
return cli_EINVAL();
|
||||||
|
@ -444,6 +446,13 @@ static int ctl_link_parse_properties(struct ctl_link *l,
|
||||||
&friendly_name);
|
&friendly_name);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return cli_log_parser(r);
|
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")) {
|
} else if (!strcmp(t, "P2PScanning")) {
|
||||||
r = bus_message_read_basic_variant(m, "b",
|
r = bus_message_read_basic_variant(m, "b",
|
||||||
&p2p_scanning);
|
&p2p_scanning);
|
||||||
|
@ -494,6 +503,9 @@ static int ctl_link_parse_properties(struct ctl_link *l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (managed_set)
|
||||||
|
l->managed = managed;
|
||||||
|
|
||||||
if (p2p_scanning_set)
|
if (p2p_scanning_set)
|
||||||
l->p2p_scanning = p2p_scanning;
|
l->p2p_scanning = p2p_scanning;
|
||||||
|
|
||||||
|
@ -620,6 +632,63 @@ int ctl_link_set_wfd_subelements(struct ctl_link *l, const char *val)
|
||||||
return 0;
|
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)
|
int ctl_link_set_p2p_scanning(struct ctl_link *l, bool val)
|
||||||
{
|
{
|
||||||
_sd_bus_message_unref_ sd_bus_message *m = NULL;
|
_sd_bus_message_unref_ sd_bus_message *m = NULL;
|
||||||
|
|
|
@ -71,6 +71,7 @@ struct ctl_link {
|
||||||
unsigned int ifindex;
|
unsigned int ifindex;
|
||||||
char *ifname;
|
char *ifname;
|
||||||
char *friendly_name;
|
char *friendly_name;
|
||||||
|
bool managed;
|
||||||
char *wfd_subelements;
|
char *wfd_subelements;
|
||||||
bool p2p_scanning;
|
bool p2p_scanning;
|
||||||
};
|
};
|
||||||
|
@ -78,6 +79,7 @@ struct ctl_link {
|
||||||
#define link_from_dlist(_l) shl_dlist_entry((_l), struct ctl_link, list);
|
#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_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_wfd_subelements(struct ctl_link *l, const char *val);
|
||||||
int ctl_link_set_p2p_scanning(struct ctl_link *l, bool val);
|
int ctl_link_set_p2p_scanning(struct ctl_link *l, bool val);
|
||||||
|
|
||||||
|
|
|
@ -84,19 +84,20 @@ static int cmd_list(char **args, unsigned int n)
|
||||||
|
|
||||||
/* list links */
|
/* list links */
|
||||||
|
|
||||||
cli_printf("%6s %-24s %-30s\n",
|
cli_printf("%6s %-24s %-30s %-10s\n",
|
||||||
"LINK", "INTERFACE", "FRIENDLY-NAME");
|
"LINK", "INTERFACE", "FRIENDLY-NAME", "MANAGED");
|
||||||
|
|
||||||
shl_dlist_for_each(i, &wifi->links) {
|
shl_dlist_for_each(i, &wifi->links) {
|
||||||
l = link_from_dlist(i);
|
l = link_from_dlist(i);
|
||||||
++link_cnt;
|
++link_cnt;
|
||||||
|
|
||||||
cli_printf("%6s %-24s %-30s\n",
|
cli_printf("%6s %-24s %-30s %-10s\n",
|
||||||
l->label,
|
l->label,
|
||||||
shl_isempty(l->ifname) ?
|
shl_isempty(l->ifname) ?
|
||||||
"<unknown>" : l->ifname,
|
"<unknown>" : l->ifname,
|
||||||
shl_isempty(l->friendly_name) ?
|
shl_isempty(l->friendly_name) ?
|
||||||
"<unknown>" : l->friendly_name);
|
"<unknown>" : l->friendly_name,
|
||||||
|
l->managed ? "yes": "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
cli_printf("\n");
|
cli_printf("\n");
|
||||||
|
@ -157,6 +158,7 @@ static int cmd_show(char **args, unsigned int n)
|
||||||
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
|
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
|
||||||
if (l->wfd_subelements && *l->wfd_subelements)
|
if (l->wfd_subelements && *l->wfd_subelements)
|
||||||
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
|
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
|
||||||
|
cli_printf("Managed=%d\n", l->managed);
|
||||||
} else if (p) {
|
} else if (p) {
|
||||||
cli_printf("Peer=%s\n", p->label);
|
cli_printf("Peer=%s\n", p->label);
|
||||||
if (p->p2p_mac && *p->p2p_mac)
|
if (p->p2p_mac && *p->p2p_mac)
|
||||||
|
@ -210,6 +212,11 @@ static int cmd_run(char **args, unsigned int n)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
run_on(l);
|
run_on(l);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -240,11 +247,37 @@ static int cmd_bind(char **args, unsigned int n)
|
||||||
if (!l)
|
if (!l)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
run_on(l);
|
run_on(l);
|
||||||
|
|
||||||
return 0;
|
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
|
* cmd: quit/exit
|
||||||
*/
|
*/
|
||||||
|
@ -341,6 +374,7 @@ static const struct cli_cmd cli_cmds[] = {
|
||||||
{ "show", "<link|peer>", CLI_M, CLI_LESS, 1, cmd_show, "Show detailed object information" },
|
{ "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" },
|
{ "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" },
|
{ "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" },
|
{ "quit", NULL, CLI_Y, CLI_MORE, 0, cmd_quit, "Quit program" },
|
||||||
{ "exit", NULL, CLI_Y, CLI_MORE, 0, cmd_quit, NULL },
|
{ "exit", NULL, CLI_Y, CLI_MORE, 0, cmd_quit, NULL },
|
||||||
{ "help", NULL, CLI_M, CLI_MORE, 0, NULL, "Print help" },
|
{ "help", NULL, CLI_M, CLI_MORE, 0, NULL, "Print help" },
|
||||||
|
|
|
@ -52,19 +52,20 @@ static int cmd_list(char **args, unsigned int n)
|
||||||
|
|
||||||
/* list links */
|
/* list links */
|
||||||
|
|
||||||
cli_printf("%6s %-24s %-30s\n",
|
cli_printf("%6s %-24s %-30s %-10s\n",
|
||||||
"LINK", "INTERFACE", "FRIENDLY-NAME");
|
"LINK", "INTERFACE", "FRIENDLY-NAME", "MANAGED");
|
||||||
|
|
||||||
shl_dlist_for_each(i, &wifi->links) {
|
shl_dlist_for_each(i, &wifi->links) {
|
||||||
l = link_from_dlist(i);
|
l = link_from_dlist(i);
|
||||||
++link_cnt;
|
++link_cnt;
|
||||||
|
|
||||||
cli_printf("%6s %-24s %-30s\n",
|
cli_printf("%6s %-24s %-30s %-10s\n",
|
||||||
l->label,
|
l->label,
|
||||||
shl_isempty(l->ifname) ?
|
shl_isempty(l->ifname) ?
|
||||||
"<unknown>" : l->ifname,
|
"<unknown>" : l->ifname,
|
||||||
shl_isempty(l->friendly_name) ?
|
shl_isempty(l->friendly_name) ?
|
||||||
"<unknown>" : l->friendly_name);
|
"<unknown>" : l->friendly_name,
|
||||||
|
l->managed ? "yes": "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
cli_printf("\n");
|
cli_printf("\n");
|
||||||
|
@ -157,6 +158,7 @@ static int cmd_show(char **args, unsigned int n)
|
||||||
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
|
cli_printf("P2PScanning=%d\n", l->p2p_scanning);
|
||||||
if (l->wfd_subelements && *l->wfd_subelements)
|
if (l->wfd_subelements && *l->wfd_subelements)
|
||||||
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
|
cli_printf("WfdSubelements=%s\n", l->wfd_subelements);
|
||||||
|
cli_printf("Managed=%d\n", l->managed);
|
||||||
} else if (p) {
|
} else if (p) {
|
||||||
cli_printf("Peer=%s\n", p->label);
|
cli_printf("Peer=%s\n", p->label);
|
||||||
if (p->p2p_mac && *p->p2p_mac)
|
if (p->p2p_mac && *p->p2p_mac)
|
||||||
|
@ -212,9 +214,53 @@ static int cmd_set_friendly_name(char **args, unsigned int n)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ctl_link_set_friendly_name(l, name);
|
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
|
* cmd: p2p-scan
|
||||||
*/
|
*/
|
||||||
|
@ -243,6 +289,11 @@ static int cmd_p2p_scan(char **args, unsigned int n)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ctl_link_set_p2p_scanning(l, !stop);
|
return ctl_link_set_p2p_scanning(l, !stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +341,11 @@ static int cmd_connect(char **args, unsigned int n)
|
||||||
pin = "";
|
pin = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!p->l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", p->l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ctl_peer_connect(p, prov, pin);
|
return ctl_peer_connect(p, prov, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,6 +368,11 @@ static int cmd_disconnect(char **args, unsigned int n)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!p->l->managed) {
|
||||||
|
cli_printf("link %s not managed\n", p->l->label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ctl_peer_disconnect(p);
|
return ctl_peer_disconnect(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,6 +395,7 @@ static const struct cli_cmd cli_cmds[] = {
|
||||||
{ "select", "[link]", CLI_Y, CLI_LESS, 1, cmd_select, "Select default link" },
|
{ "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" },
|
{ "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-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" },
|
{ "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" },
|
{ "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" },
|
{ "disconnect", "<peer>", CLI_M, CLI_EQUAL, 1, cmd_disconnect, "Disconnect from peer" },
|
||||||
|
|
|
@ -231,4 +231,9 @@ extern const char *LOG_SUBSYSTEM;
|
||||||
#define log_vERR(_r) \
|
#define log_vERR(_r) \
|
||||||
((void)log_ERR(_r))
|
((void)log_ERR(_r))
|
||||||
|
|
||||||
|
#define log_EUNMANAGED() \
|
||||||
|
(log_error("interface unmanaged"), -EFAULT)
|
||||||
|
#define log_vEUNMANAGED() \
|
||||||
|
((void)log_EUNMANAGED())
|
||||||
|
|
||||||
#endif /* SHL_LOG_H */
|
#endif /* SHL_LOG_H */
|
||||||
|
|
|
@ -571,6 +571,42 @@ static int link_dbus_set_friendly_name(sd_bus *bus,
|
||||||
return link_set_friendly_name(l, name);
|
return link_set_friendly_name(l, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int link_dbus_get_managed(sd_bus *bus,
|
||||||
|
const char *path,
|
||||||
|
const char *interface,
|
||||||
|
const char *property,
|
||||||
|
sd_bus_message *reply,
|
||||||
|
void *data,
|
||||||
|
sd_bus_error *err)
|
||||||
|
{
|
||||||
|
struct link *l = data;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = sd_bus_message_append(reply, "b", link_get_managed(l));
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
struct link *l = data;
|
||||||
|
int val, r;
|
||||||
|
|
||||||
|
r = sd_bus_message_read(value, "b", &val);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
return link_set_managed(l, val);
|
||||||
|
}
|
||||||
|
|
||||||
static int link_dbus_get_p2p_scanning(sd_bus *bus,
|
static int link_dbus_get_p2p_scanning(sd_bus *bus,
|
||||||
const char *path,
|
const char *path,
|
||||||
const char *interface,
|
const char *interface,
|
||||||
|
@ -662,6 +698,12 @@ static const sd_bus_vtable link_dbus_vtable[] = {
|
||||||
link_dbus_set_friendly_name,
|
link_dbus_set_friendly_name,
|
||||||
0,
|
0,
|
||||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||||
|
SD_BUS_WRITABLE_PROPERTY("Managed",
|
||||||
|
"b",
|
||||||
|
link_dbus_get_managed,
|
||||||
|
link_dbus_set_managed,
|
||||||
|
0,
|
||||||
|
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||||
SD_BUS_WRITABLE_PROPERTY("P2PScanning",
|
SD_BUS_WRITABLE_PROPERTY("P2PScanning",
|
||||||
"b",
|
"b",
|
||||||
link_dbus_get_p2p_scanning,
|
link_dbus_get_p2p_scanning,
|
||||||
|
|
|
@ -100,6 +100,8 @@ int link_new(struct manager *m,
|
||||||
if (out)
|
if (out)
|
||||||
*out = l;
|
*out = l;
|
||||||
|
|
||||||
|
l->public = true;
|
||||||
|
link_dbus_added(l);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -116,6 +118,9 @@ void link_free(struct link *l)
|
||||||
|
|
||||||
link_set_managed(l, false);
|
link_set_managed(l, false);
|
||||||
|
|
||||||
|
link_dbus_removed(l);
|
||||||
|
l->public = false;
|
||||||
|
|
||||||
if (shl_htable_remove_uint(&l->m->links, l->ifindex, NULL)) {
|
if (shl_htable_remove_uint(&l->m->links, l->ifindex, NULL)) {
|
||||||
log_info("remove link: %s", l->ifname);
|
log_info("remove link: %s", l->ifname);
|
||||||
--l->m->link_cnt;
|
--l->m->link_cnt;
|
||||||
|
@ -159,14 +164,19 @@ int link_set_config_methods(struct link *l, char *config_methods)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void link_set_managed(struct link *l, bool set)
|
bool link_get_managed(struct link *l)
|
||||||
|
{
|
||||||
|
return l->managed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int link_set_managed(struct link *l, bool set)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!l)
|
if (!l)
|
||||||
return log_vEINVAL();
|
return log_EINVAL();
|
||||||
if (l->managed == set)
|
if (l->managed == set)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
if (set) {
|
if (set) {
|
||||||
log_info("manage link %s", l->ifname);
|
log_info("manage link %s", l->ifname);
|
||||||
|
@ -174,7 +184,7 @@ void link_set_managed(struct link *l, bool set)
|
||||||
r = supplicant_start(l->s);
|
r = supplicant_start(l->s);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error("cannot start supplicant on %s", l->ifname);
|
log_error("cannot start supplicant on %s", l->ifname);
|
||||||
return;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_info("link %s no longer managed", l->ifname);
|
log_info("link %s no longer managed", l->ifname);
|
||||||
|
@ -182,6 +192,7 @@ void link_set_managed(struct link *l, bool set)
|
||||||
}
|
}
|
||||||
|
|
||||||
l->managed = set;
|
l->managed = set;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int link_renamed(struct link *l, const char *ifname)
|
int link_renamed(struct link *l, const char *ifname)
|
||||||
|
@ -216,6 +227,9 @@ int link_set_friendly_name(struct link *l, const char *name)
|
||||||
if (!l || !name || !*name)
|
if (!l || !name || !*name)
|
||||||
return log_EINVAL();
|
return log_EINVAL();
|
||||||
|
|
||||||
|
if (!l->managed)
|
||||||
|
return log_EUNMANAGED();
|
||||||
|
|
||||||
t = strdup(name);
|
t = strdup(name);
|
||||||
if (!t)
|
if (!t)
|
||||||
return log_ENOMEM();
|
return log_ENOMEM();
|
||||||
|
@ -251,6 +265,9 @@ int link_set_wfd_subelements(struct link *l, const char *val)
|
||||||
if (!l || !val)
|
if (!l || !val)
|
||||||
return log_EINVAL();
|
return log_EINVAL();
|
||||||
|
|
||||||
|
if (!l->managed)
|
||||||
|
return log_EUNMANAGED();
|
||||||
|
|
||||||
t = strdup(val);
|
t = strdup(val);
|
||||||
if (!t)
|
if (!t)
|
||||||
return log_ENOMEM();
|
return log_ENOMEM();
|
||||||
|
@ -283,6 +300,9 @@ int link_set_p2p_scanning(struct link *l, bool set)
|
||||||
if (!l)
|
if (!l)
|
||||||
return log_EINVAL();
|
return log_EINVAL();
|
||||||
|
|
||||||
|
if (!l->managed)
|
||||||
|
return log_EUNMANAGED();
|
||||||
|
|
||||||
if (set) {
|
if (set) {
|
||||||
return supplicant_p2p_start_scan(l->s);
|
return supplicant_p2p_start_scan(l->s);
|
||||||
} else {
|
} else {
|
||||||
|
@ -293,7 +313,16 @@ int link_set_p2p_scanning(struct link *l, bool set)
|
||||||
|
|
||||||
bool link_get_p2p_scanning(struct link *l)
|
bool link_get_p2p_scanning(struct link *l)
|
||||||
{
|
{
|
||||||
return l && supplicant_p2p_scanning(l->s);
|
if (!l) {
|
||||||
|
log_vEINVAL();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!l->managed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return supplicant_p2p_scanning(l->s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void link_supplicant_started(struct link *l)
|
void link_supplicant_started(struct link *l)
|
||||||
|
@ -301,9 +330,8 @@ void link_supplicant_started(struct link *l)
|
||||||
if (!l || l->public)
|
if (!l || l->public)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log_debug("link %s started", l->ifname);
|
link_set_friendly_name(l, l->m->friendly_name);
|
||||||
l->public = true;
|
log_info("link %s managed", l->ifname);
|
||||||
link_dbus_added(l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void link_supplicant_stopped(struct link *l)
|
void link_supplicant_stopped(struct link *l)
|
||||||
|
@ -311,9 +339,7 @@ void link_supplicant_stopped(struct link *l)
|
||||||
if (!l || !l->public)
|
if (!l || !l->public)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log_debug("link %s stopped", l->ifname);
|
log_info("link %s unmanaged", l->ifname);
|
||||||
link_dbus_removed(l);
|
|
||||||
l->public = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void link_supplicant_p2p_scan_changed(struct link *l, bool new_value)
|
void link_supplicant_p2p_scan_changed(struct link *l, bool new_value)
|
||||||
|
|
|
@ -44,6 +44,7 @@ const char *interface_name = NULL;
|
||||||
const char *config_methods = NULL;
|
const char *config_methods = NULL;
|
||||||
unsigned int arg_wpa_loglevel = LOG_NOTICE;
|
unsigned int arg_wpa_loglevel = LOG_NOTICE;
|
||||||
bool use_dev = false;
|
bool use_dev = false;
|
||||||
|
bool lazy_managed = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Manager Handling
|
* Manager Handling
|
||||||
|
@ -109,9 +110,9 @@ static void manager_add_udev_link(struct manager *m,
|
||||||
link_use_dev(l);
|
link_use_dev(l);
|
||||||
|
|
||||||
#ifdef RELY_UDEV
|
#ifdef RELY_UDEV
|
||||||
if (udev_device_has_tag(d, "miracle")) {
|
if (udev_device_has_tag(d, "miracle") && !lazy_managed) {
|
||||||
#else
|
#else
|
||||||
if (!interface_name || !strcmp(interface_name, ifname)) {
|
if ((!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed) {
|
||||||
#endif
|
#endif
|
||||||
link_set_managed(l, true);
|
link_set_managed(l, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,12 +153,12 @@ static int manager_udev_fn(sd_event_source *source,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RELY_UDEV
|
#ifdef RELY_UDEV
|
||||||
if (udev_device_has_tag(d, "miracle"))
|
if (udev_device_has_tag(d, "miracle") && !lazy_managed)
|
||||||
link_set_managed(l, true);
|
link_set_managed(l, true);
|
||||||
else
|
else
|
||||||
link_set_managed(l, false);
|
link_set_managed(l, false);
|
||||||
#else
|
#else
|
||||||
if (!interface_name || !strcmp(interface_name, ifname)) {
|
if ((!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed) {
|
||||||
link_set_managed(l, true);
|
link_set_managed(l, true);
|
||||||
} else {
|
} else {
|
||||||
log_debug("ignored device: %s", ifname);
|
log_debug("ignored device: %s", ifname);
|
||||||
|
@ -477,6 +478,7 @@ static int help(void)
|
||||||
"\n"
|
"\n"
|
||||||
" --wpa-loglevel <lvl wpa_supplicant log-level\n"
|
" --wpa-loglevel <lvl wpa_supplicant log-level\n"
|
||||||
" --use-dev enable workaround for 'no ifname' issue\n"
|
" --use-dev enable workaround for 'no ifname' issue\n"
|
||||||
|
" --lazy-managed manage interface only when user decide to do\n"
|
||||||
, program_invocation_short_name);
|
, program_invocation_short_name);
|
||||||
/*
|
/*
|
||||||
* 80-char barrier:
|
* 80-char barrier:
|
||||||
|
@ -495,6 +497,7 @@ static int parse_argv(int argc, char *argv[])
|
||||||
ARG_WPA_LOGLEVEL,
|
ARG_WPA_LOGLEVEL,
|
||||||
ARG_USE_DEV,
|
ARG_USE_DEV,
|
||||||
ARG_CONFIG_METHODS,
|
ARG_CONFIG_METHODS,
|
||||||
|
ARG_LAZY_MANAGED,
|
||||||
};
|
};
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
@ -506,6 +509,7 @@ static int parse_argv(int argc, char *argv[])
|
||||||
{ "interface", required_argument, NULL, 'i' },
|
{ "interface", required_argument, NULL, 'i' },
|
||||||
{ "use-dev", no_argument, NULL, ARG_USE_DEV },
|
{ "use-dev", no_argument, NULL, ARG_USE_DEV },
|
||||||
{ "config-methods", required_argument, NULL, ARG_CONFIG_METHODS },
|
{ "config-methods", required_argument, NULL, ARG_CONFIG_METHODS },
|
||||||
|
{ "lazy-managed", no_argument, NULL, ARG_LAZY_MANAGED },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
int c;
|
int c;
|
||||||
|
@ -531,6 +535,8 @@ static int parse_argv(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case ARG_CONFIG_METHODS:
|
case ARG_CONFIG_METHODS:
|
||||||
config_methods = optarg;
|
config_methods = optarg;
|
||||||
|
case ARG_LAZY_MANAGED:
|
||||||
|
lazy_managed = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_WPA_LOGLEVEL:
|
case ARG_WPA_LOGLEVEL:
|
||||||
|
|
|
@ -159,7 +159,8 @@ void link_free(struct link *l);
|
||||||
void link_use_dev(struct link *l);
|
void link_use_dev(struct link *l);
|
||||||
bool link_is_using_dev(struct link *l);
|
bool link_is_using_dev(struct link *l);
|
||||||
|
|
||||||
void link_set_managed(struct link *l, bool set);
|
int link_set_managed(struct link *l, bool set);
|
||||||
|
bool link_get_managed(struct link *l);
|
||||||
int link_renamed(struct link *l, const char *ifname);
|
int link_renamed(struct link *l, const char *ifname);
|
||||||
|
|
||||||
int link_set_config_methods(struct link *l, char *config_methods);
|
int link_set_config_methods(struct link *l, char *config_methods);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue