From 0446b9206238e24a5019483a2e2aea27d41f75dc Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Dec 2007 22:36:10 +0100 Subject: [PATCH] Add basic DHCP infrastructure --- include/Makefile.am | 2 +- include/dhcp.h | 44 ++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/connman.h | 7 ++++++ src/dhcp.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 include/dhcp.h create mode 100644 src/dhcp.c diff --git a/include/Makefile.am b/include/Makefile.am index ece5af1..627ab0a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,7 +1,7 @@ includedir = @includedir@/connman -noinst_HEADERS = plugin.h iface.h +noinst_HEADERS = plugin.h iface.h dhcp.h MAINTAINERCLEANFILES = Makefile.in diff --git a/include/dhcp.h b/include/dhcp.h new file mode 100644 index 0000000..337746b --- /dev/null +++ b/include/dhcp.h @@ -0,0 +1,44 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CONNMAN_DHCP_H +#define __CONNMAN_DHCP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct connman_dhcp_driver { + const char *name; + int (*request) (struct connman_iface *iface); + int (*release) (struct connman_iface *iface); +}; + +extern int connman_dhcp_register(struct connman_dhcp_driver *driver); +extern void connman_dhcp_unregister(struct connman_dhcp_driver *driver); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMAN_DHCP_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 5233c0b..05f342b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,7 @@ dbus_DATA = connman.conf sbin_PROGRAMS = connmand -connmand_SOURCES = main.c connman.h plugin.c iface.c +connmand_SOURCES = main.c connman.h plugin.c iface.c dhcp.c connmand_LDADD = @HAL_LIBS@ @GDBUS_LIBS@ @GMODULE_LIBS@ diff --git a/src/connman.h b/src/connman.h index 641b0a2..1cd6c16 100644 --- a/src/connman.h +++ b/src/connman.h @@ -24,6 +24,8 @@ #define DBG(fmt, arg...) printf("%s: " fmt "\n" , __FUNCTION__ , ## arg) //#define DBG(fmt, arg...) +#include + #define CONNMAN_SERVICE "org.freedesktop.connman" #define CONNMAN_MANAGER_PATH "/" @@ -41,3 +43,8 @@ void __connman_plugin_cleanup(void); int __connman_iface_init(DBusConnection *conn); void __connman_iface_cleanup(void); + +#include + +int __connman_dhcp_request(struct connman_iface *iface); +int __connman_dhcp_release(struct connman_iface *iface); diff --git a/src/dhcp.c b/src/dhcp.c new file mode 100644 index 0000000..5a6e5c9 --- /dev/null +++ b/src/dhcp.c @@ -0,0 +1,66 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "connman.h" + +static GSList *drivers = NULL; + +int connman_dhcp_register(struct connman_dhcp_driver *driver) +{ + DBG("driver %p", driver); + + drivers = g_slist_append(drivers, driver); + + return 0; +} + +void connman_dhcp_unregister(struct connman_dhcp_driver *driver) +{ + DBG("driver %p", driver); + + drivers = g_slist_remove(drivers, driver); +} + +int __connman_dhcp_request(struct connman_iface *iface) +{ + struct connman_dhcp_driver *driver = g_slist_nth_data(drivers, 0); + + if (driver && driver->request) + return driver->request(iface); + + return -1; +} + +int __connman_dhcp_release(struct connman_iface *iface) +{ + struct connman_dhcp_driver *driver = g_slist_nth_data(drivers, 0); + + if (driver && driver->release) + return driver->release(iface); + + return -1; +} -- 1.7.9.5