5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 struct connman_ipconfig {
32 enum connman_ipconfig_method method;
36 * connman_ipconfig_create:
38 * Allocate a new ipconfig structure.
40 * Returns: a newly-allocated #connman_ipconfig structure
42 struct connman_ipconfig *connman_ipconfig_create(void)
44 struct connman_ipconfig *ipconfig;
48 ipconfig = g_try_new0(struct connman_ipconfig, 1);
52 DBG("ipconfig %p", ipconfig);
58 * connman_ipconfig_ref:
59 * @ipconfig: ipconfig structure
61 * Increase reference counter of ipconfig
63 struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
65 g_atomic_int_inc(&ipconfig->refcount);
71 * connman_ipconfig_unref:
72 * @ipconfig: ipconfig structure
74 * Decrease reference counter of ipconfig
76 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
78 if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
83 const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
86 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
88 case CONNMAN_IPCONFIG_METHOD_OFF:
90 case CONNMAN_IPCONFIG_METHOD_STATIC:
92 case CONNMAN_IPCONFIG_METHOD_DHCP:
99 enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
101 if (g_strcmp0(method, "off") == 0)
102 return CONNMAN_IPCONFIG_METHOD_OFF;
103 else if (g_strcmp0(method, "static") == 0)
104 return CONNMAN_IPCONFIG_METHOD_STATIC;
105 else if (g_strcmp0(method, "dhcp") == 0)
106 return CONNMAN_IPCONFIG_METHOD_DHCP;
108 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
111 static void append_variant(DBusMessageIter *iter, const char *prefix,
112 const char *key, int type, void *val)
116 if (prefix == NULL) {
117 connman_dbus_dict_append_variant(iter, key, type, val);
121 str = g_strdup_printf("%s%s", prefix, key);
123 connman_dbus_dict_append_variant(iter, str, type, val);
128 void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
129 DBusMessageIter *iter, const char *prefix)
133 str = __connman_ipconfig_method2string(ipconfig->method);
137 append_variant(iter, prefix, "Method", DBUS_TYPE_STRING, &str);
140 int __connman_ipconfig_set_ipv4(struct connman_ipconfig *ipconfig,
141 const char *key, DBusMessageIter *value)
143 int type = dbus_message_iter_get_arg_type(value);
145 DBG("ipconfig %p key %s type %d", ipconfig, key, type);
147 if (g_strcmp0(key, "Method") == 0) {
150 if (type != DBUS_TYPE_STRING)
153 dbus_message_iter_get_basic(value, &method);
155 ipconfig->method = __connman_ipconfig_string2method(method);
162 static GSList *driver_list = NULL;
164 static gint compare_priority(gconstpointer a, gconstpointer b)
166 const struct connman_ipconfig_driver *driver1 = a;
167 const struct connman_ipconfig_driver *driver2 = b;
169 return driver2->priority - driver1->priority;
173 * connman_ipconfig_driver_register:
174 * @driver: IP configuration driver
176 * Register a new IP configuration driver
178 * Returns: %0 on success
180 int connman_ipconfig_driver_register(struct connman_ipconfig_driver *driver)
182 DBG("driver %p name %s", driver, driver->name);
184 driver_list = g_slist_insert_sorted(driver_list, driver,
191 * connman_ipconfig_driver_unregister:
192 * @driver: IP configuration driver
194 * Remove a previously registered IP configuration driver.
196 void connman_ipconfig_driver_unregister(struct connman_ipconfig_driver *driver)
198 DBG("driver %p name %s", driver, driver->name);
200 driver_list = g_slist_remove(driver_list, driver);