mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-13 10:41:55 +00:00
miracle-wifid: add Link.P2PState for checking P2P supporting status
This commit is contained in:
parent
ed490f181b
commit
aa499be0dc
4 changed files with 64 additions and 1 deletions
|
@ -631,6 +631,24 @@ static int link_dbus_unmanage(sd_bus_message *msg,
|
|||
return sd_bus_reply_method_return(msg, NULL);
|
||||
}
|
||||
|
||||
static int link_dbus_get_p2p_state(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, "i", link_get_p2p_state(l));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int link_dbus_get_p2p_scanning(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
|
@ -742,6 +760,11 @@ static const sd_bus_vtable link_dbus_vtable[] = {
|
|||
link_dbus_get_managed,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("P2PState",
|
||||
"i",
|
||||
link_dbus_get_p2p_state,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("P2PScanning",
|
||||
"b",
|
||||
link_dbus_get_p2p_scanning,
|
||||
|
|
|
@ -155,6 +155,26 @@ bool link_is_using_dev(struct link *l)
|
|||
return l->use_dev;
|
||||
}
|
||||
|
||||
int link_get_p2p_state(struct link *l)
|
||||
{
|
||||
return l->p2p_state;
|
||||
}
|
||||
|
||||
int link_set_p2p_state(struct link *l, int state)
|
||||
{
|
||||
if (!l)
|
||||
return log_EINVAL();
|
||||
if (l->p2p_state == state)
|
||||
return 0;
|
||||
if(-1 > state || 1 < state)
|
||||
return log_EINVAL();
|
||||
|
||||
l->p2p_state = state;
|
||||
link_dbus_properties_changed(l, "P2PState", NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool link_get_managed(struct link *l)
|
||||
{
|
||||
return l->managed;
|
||||
|
@ -184,6 +204,19 @@ int link_set_managed(struct link *l, bool set)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void link_supplicant_p2p_state_known(struct link *l, int state)
|
||||
{
|
||||
if (!l)
|
||||
return log_vEINVAL();
|
||||
if (l->p2p_state == state)
|
||||
return;
|
||||
if(-1 > state || 1 < state)
|
||||
return log_vEINVAL();
|
||||
|
||||
l->p2p_state = state;
|
||||
link_dbus_properties_changed(l, "P2PState", NULL);
|
||||
}
|
||||
|
||||
void link_supplicant_managed(struct link *l)
|
||||
{
|
||||
if(l->managed) {
|
||||
|
|
|
@ -1702,12 +1702,14 @@ static int supplicant_status_fn(struct wpas *w,
|
|||
|
||||
if (!p2p_state) {
|
||||
log_warning("wpa_supplicant or driver does not support P2P");
|
||||
link_supplicant_p2p_state_known(s->l, -1);
|
||||
} else if (!strcmp(p2p_state, "DISABLED")) {
|
||||
log_warning("P2P support disabled on given interface");
|
||||
link_supplicant_p2p_state_known(s->l, -1);
|
||||
} else {
|
||||
s->has_p2p = true;
|
||||
|
||||
link_supplicant_managed(s->l);
|
||||
link_supplicant_p2p_state_known(s->l, 1);
|
||||
|
||||
r = wpas_message_new_request(s->bus_global,
|
||||
"SET",
|
||||
|
@ -2579,6 +2581,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? */
|
||||
|
|
|
@ -130,6 +130,7 @@ struct link {
|
|||
char *friendly_name;
|
||||
char *wfd_subelements;
|
||||
char *mac_addr;
|
||||
int p2p_state; /* 0: unknown, 1: supported, -1: unsupproted */
|
||||
|
||||
size_t peer_cnt;
|
||||
struct shl_htable peers;
|
||||
|
@ -170,12 +171,15 @@ int link_set_wfd_subelements(struct link *l, const char *val);
|
|||
const char *link_get_wfd_subelements(struct link *l);
|
||||
int link_set_p2p_scanning(struct link *l, bool set);
|
||||
bool link_get_p2p_scanning(struct link *l);
|
||||
int link_get_p2p_state(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);
|
||||
/* 0: unknown, -1: unsupported, 1: supported */
|
||||
void link_supplicant_p2p_state_known(struct link *l, int state);
|
||||
|
||||
_shl_sentinel_
|
||||
void link_dbus_properties_changed(struct link *l, const char *prop, ...);
|
||||
|
|
Loading…
Reference in a new issue