mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-13 07:11:55 +00:00
miracle-wifid: add MACAddress property to link
This commit is contained in:
parent
1919de3158
commit
df336c8c51
4 changed files with 49 additions and 1 deletions
|
@ -512,6 +512,24 @@ static int link_dbus_get_interface_index(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int link_dbus_get_mac_addr(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_basic(reply, 's', l->mac_addr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int link_dbus_get_interface_name(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
|
@ -686,6 +704,11 @@ static const sd_bus_vtable link_dbus_vtable[] = {
|
|||
link_dbus_get_interface_index,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("MACAddress",
|
||||
"s",
|
||||
link_dbus_get_mac_addr,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("InterfaceName",
|
||||
"s",
|
||||
link_dbus_get_interface_name,
|
||||
|
|
|
@ -57,6 +57,7 @@ struct peer *link_find_peer_by_label(struct link *l, const char *label)
|
|||
int link_new(struct manager *m,
|
||||
unsigned int ifindex,
|
||||
const char *ifname,
|
||||
const char *mac_addr,
|
||||
struct link **out)
|
||||
{
|
||||
struct link *l;
|
||||
|
@ -84,6 +85,12 @@ int link_new(struct manager *m,
|
|||
goto error;
|
||||
}
|
||||
|
||||
l->mac_addr = strdup(mac_addr);
|
||||
if (!l->mac_addr) {
|
||||
r = log_ENOMEM();
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = supplicant_new(l, &l->s);
|
||||
if (r < 0)
|
||||
goto error;
|
||||
|
@ -131,6 +138,7 @@ void link_free(struct link *l)
|
|||
/* link_set_managed(l, false) already removed all peers */
|
||||
shl_htable_clear_str(&l->peers, NULL, NULL);
|
||||
|
||||
free(l->mac_addr);
|
||||
free(l->wfd_subelements);
|
||||
free(l->friendly_name);
|
||||
free(l->ifname);
|
||||
|
@ -308,6 +316,14 @@ bool link_get_p2p_scanning(struct link *l)
|
|||
return supplicant_p2p_scanning(l->s);
|
||||
}
|
||||
|
||||
const char *link_get_mac_addr(struct link *l)
|
||||
{
|
||||
if (!l)
|
||||
return NULL;
|
||||
|
||||
return l->mac_addr;
|
||||
}
|
||||
|
||||
void link_supplicant_started(struct link *l)
|
||||
{
|
||||
if (!l || l->public)
|
||||
|
|
|
@ -80,6 +80,8 @@ static void manager_add_udev_link(struct manager *m,
|
|||
struct link *l;
|
||||
unsigned int ifindex;
|
||||
const char *ifname;
|
||||
const char *mac_addr;
|
||||
char buf[18];
|
||||
int r;
|
||||
|
||||
ifindex = ifindex_from_udev_device(d);
|
||||
|
@ -98,7 +100,11 @@ static void manager_add_udev_link(struct manager *m,
|
|||
if (shl_startswith(ifname, "p2p-"))
|
||||
return;
|
||||
|
||||
r = link_new(m, ifindex, ifname, &l);
|
||||
mac_addr = udev_device_get_property_value(d, "ID_NET_NAME_MAC");
|
||||
mac_addr = mac_addr + strlen(mac_addr) - 12;
|
||||
snprintf(buf, sizeof(buf), "%.2s:%.2s:%.2s:%.2s:%.2s:%.2s", mac_addr, mac_addr + 2, mac_addr + 4, mac_addr + 6, mac_addr + 8, mac_addr + 10);
|
||||
|
||||
r = link_new(m, ifindex, ifname, buf, &l);
|
||||
if (r < 0)
|
||||
return;
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ struct link {
|
|||
char *ifname;
|
||||
char *friendly_name;
|
||||
char *wfd_subelements;
|
||||
char *mac_addr;
|
||||
|
||||
size_t peer_cnt;
|
||||
struct shl_htable peers;
|
||||
|
@ -151,6 +152,7 @@ struct peer *link_find_peer_by_label(struct link *l, const char *label);
|
|||
int link_new(struct manager *m,
|
||||
unsigned int ifindex,
|
||||
const char *ifname,
|
||||
const char *mac_addr,
|
||||
struct link **out);
|
||||
void link_free(struct link *l);
|
||||
|
||||
|
@ -168,6 +170,7 @@ 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);
|
||||
const char *link_get_mac_addr(struct link *l);
|
||||
|
||||
void link_supplicant_started(struct link *l);
|
||||
void link_supplicant_stopped(struct link *l);
|
||||
|
|
Loading…
Reference in a new issue