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

Initial MiracleCast Implementation

This initial commit contains the main "miracled" daemon that does
link-management and peer-discovery/control. The "miraclectl" tool can be
used to control this daemon during runtime.

Note that this implementation is still missing a lot of stuff. All it
currently does is provide link-management and basic peer-discovery.
Following commits will hook everything else up.

The actual Miracast/Wifi-Display related runtime control is not being
worked on, yet. Feel free to use the proof-of-concept from the OpenWFD
repository. The MiracleCast implementation will not get any such
functionality unless the basic link-management is properly working.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
David Herrmann 2014-02-06 16:43:11 +01:00
commit 051b584746
35 changed files with 13147 additions and 0 deletions

131
src/miracled.h Normal file
View file

@ -0,0 +1,131 @@
/*
* MiracleCast - Wifi-Display/Miracast Implementation
*
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-event.h>
#include "miracle.h"
#include "shl_dlist.h"
#include "shl_htable.h"
#ifndef MIRACLED_H
#define MIRACLED_H
struct manager;
struct link;
struct peer;
struct wifi;
struct wifi_dev;
struct wifi_event;
/* peer */
struct peer {
struct shl_dlist list;
struct link *l;
unsigned int id;
char *name;
struct wifi_dev *d;
};
#define peer_from_htable(_p) \
shl_htable_offsetof((_p), struct peer, name)
#define peer_from_list(_p) \
shl_dlist_entry((_p), struct peer, list)
int peer_new_wifi(struct link *l, struct wifi_dev *d, struct peer **out);
void peer_free(struct peer *p);
void peer_process_wifi(struct peer *p, struct wifi_event *ev);
int peer_make_name(unsigned int id, char **out);
/* link */
enum link_type {
LINK_VIRTUAL,
LINK_WIFI,
LINK_CNT,
};
struct link {
struct manager *m;
unsigned int type;
char *interface;
char *name;
char *friendly_name;
struct shl_dlist peers;
struct wifi *w;
};
#define link_from_htable(_l) \
shl_htable_offsetof((_l), struct link, name)
#define LINK_FIRST_PEER(_l) (shl_dlist_empty(&(_l)->peers) ? \
NULL : peer_from_list((_l)->peers.next))
const char *link_type_to_str(unsigned int type);
unsigned int link_type_from_str(const char *str);
int link_make_name(unsigned int type, const char *interface, char **out);
int link_new(struct manager *m,
unsigned int type,
const char *interface,
struct link **out);
void link_free(struct link *l);
/* manager */
struct manager {
sd_event *event;
sd_bus *bus;
sd_event_source *sigs[_NSIG];
unsigned int peer_ids;
size_t link_cnt;
size_t peer_cnt;
struct shl_htable links;
struct shl_htable peers;
};
#define MANAGER_FIRST_LINK(_m) \
SHL_HTABLE_FIRST_MACRO(&(_m)->links, link_from_htable)
#define MANAGER_FOREACH_LINK(_i, _m) \
SHL_HTABLE_FOREACH_MACRO(_i, &(_m)->links, link_from_htable)
#define MANAGER_FOREACH_PEER(_i, _m) \
SHL_HTABLE_FOREACH_MACRO(_i, &(_m)->peers, peer_from_htable)
int manager_dbus_connect(struct manager *m);
void manager_dbus_disconnect(struct manager *m);
struct link *manager_find_link(struct manager *m, const char *name);
struct peer *manager_find_peer(struct manager *m, const char *name);
#endif /* MIRACLED_H */