summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-11-06 09:31:53 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-11-06 09:31:53 +0100
commit487dbfcf2ddbbbcf2a929289f60313683eb65dec (patch)
treea66aa944ab803c4389ae90530f871a53534ac463 /src
parent235ba3535b4417c4bdb967374934af6202f58c01 (diff)
owfd: p2pd: add dummy client
The dummy client is used to interact with the p2pd-interface infrastructure as long as we have no external programs. The dummy will be used for basic testing and development. It will get trashed once we have a real interface (or another network-manager finally picks up p2p). Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/p2pd.c6
-rw-r--r--src/p2pd.h9
-rw-r--r--src/p2pd_dummy.c93
3 files changed, 108 insertions, 0 deletions
diff --git a/src/p2pd.c b/src/p2pd.c
index 4864a0f..8a54be3 100644
--- a/src/p2pd.c
+++ b/src/p2pd.c
@@ -41,6 +41,7 @@ struct owfd_p2pd {
int sfd;
struct owfd_p2pd_interface *interface;
+ struct owfd_p2pd_dummy *dummy;
};
int owfd_p2pd_ep_add(int efd, int *fd, unsigned int events)
@@ -185,6 +186,7 @@ static int owfd_p2pd_run(struct owfd_p2pd *p2pd)
static void owfd_p2pd_teardown(struct owfd_p2pd *p2pd)
{
+ owfd_p2pd_dummy_free(p2pd->dummy);
owfd_p2pd_interface_free(p2pd->interface);
if (p2pd->sfd >= 0)
@@ -253,6 +255,10 @@ static int owfd_p2pd_setup(struct owfd_p2pd *p2pd)
if (r < 0)
goto error;
+ r = owfd_p2pd_dummy_new(&p2pd->dummy, &p2pd->config, p2pd->interface);
+ if (r < 0)
+ goto error;
+
return 0;
error:
diff --git a/src/p2pd.h b/src/p2pd.h
index a76084c..50fbe4b 100644
--- a/src/p2pd.h
+++ b/src/p2pd.h
@@ -94,6 +94,15 @@ void owfd_p2pd_interface_unregister_event_fn(struct owfd_p2pd_interface *iface,
owfd_p2pd_interface_event_fn event_fn,
void *data);
+/* dummy */
+
+struct owfd_p2pd_dummy;
+
+int owfd_p2pd_dummy_new(struct owfd_p2pd_dummy **out,
+ struct owfd_p2pd_config *config,
+ struct owfd_p2pd_interface *iface);
+void owfd_p2pd_dummy_free(struct owfd_p2pd_dummy *dummy);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/p2pd_dummy.c b/src/p2pd_dummy.c
new file mode 100644
index 0000000..c862342
--- /dev/null
+++ b/src/p2pd_dummy.c
@@ -0,0 +1,93 @@
+/*
+ * OpenWFD - Open-Source Wifi-Display Implementation
+ *
+ * Copyright (c) 2013 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 <fcntl.h>
+#include <getopt.h>
+#include <poll.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <sys/inotify.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "p2pd.h"
+#include "shared.h"
+#include "shl_log.h"
+#include "wpa.h"
+
+struct owfd_p2pd_dummy {
+ struct owfd_p2pd_config *config;
+ struct owfd_p2pd_interface *iface;
+};
+
+static void dummy_event_fn(struct owfd_p2pd_interface *iface,
+ struct owfd_wpa_event *ev,
+ void *data)
+{
+ struct owfd_p2pd_dummy *dummy = data;
+}
+
+int owfd_p2pd_dummy_new(struct owfd_p2pd_dummy **out,
+ struct owfd_p2pd_config *config,
+ struct owfd_p2pd_interface *iface)
+{
+ struct owfd_p2pd_dummy *dummy;
+ int r;
+
+ dummy = calloc(1, sizeof(*dummy));
+ if (!dummy)
+ return -ENOMEM;
+
+ dummy->config = config;
+ dummy->iface = iface;
+
+ r = owfd_p2pd_interface_register_event_fn(dummy->iface,
+ dummy_event_fn,
+ dummy);
+ if (r < 0)
+ goto err_dummy;
+
+ *out = dummy;
+ return 0;
+
+err_dummy:
+ free(dummy);
+ return r;
+}
+
+void owfd_p2pd_dummy_free(struct owfd_p2pd_dummy *dummy)
+{
+ if (!dummy)
+ return;
+
+ owfd_p2pd_interface_unregister_event_fn(dummy->iface,
+ dummy_event_fn,
+ dummy);
+ free(dummy);
+}