Add basic DHCP infrastructure
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 22 Dec 2007 21:36:10 +0000 (22:36 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 22 Dec 2007 21:36:10 +0000 (22:36 +0100)
include/Makefile.am
include/dhcp.h [new file with mode: 0644]
src/Makefile.am
src/connman.h
src/dhcp.c [new file with mode: 0644]

index ece5af1..627ab0a 100644 (file)
@@ -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 (file)
index 0000000..337746b
--- /dev/null
@@ -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 <connman/iface.h>
+
+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 */
index 5233c0b..05f342b 100644 (file)
@@ -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@
  
index 641b0a2..1cd6c16 100644 (file)
@@ -24,6 +24,8 @@
 #define DBG(fmt, arg...)  printf("%s: " fmt "\n" , __FUNCTION__ , ## arg)
 //#define DBG(fmt, arg...)
 
+#include <dbus/dbus.h>
+
 #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 <connman/dhcp.h>
+
+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 (file)
index 0000000..5a6e5c9
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include <glib.h>
+
+#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;
+}