3 * Copyright 2009 Roy Marples <roy@marples.name>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <netinet/in.h>
36 #define IF_SSIDSIZE 33
37 #define IF_BSSIDSIZE 64
41 typedef struct dhcpcd_wi_scan {
42 char bssid[IF_BSSIDSIZE];
48 char ssid[IF_SSIDSIZE];
49 struct dhcpcd_wi_scan *next;
52 typedef struct dhcpcd_if {
53 char ifname[IF_NAMESIZE];
55 char reason[REASONSIZE];
59 char ssid[IF_SSIDSIZE];
60 struct dhcpcd_if *next;
63 /* Although we use DBus, we don't have to rely on it for our API */
65 #include <dbus/dbus.h>
66 typedef DBusMessage DHCPCD_MESSAGE;
67 typedef DBusMessageIter DHCPCD_MESSAGEITER;
69 typedef struct dhcpcd_connection {
75 void (*add_watch)(struct dhcpcd_connection *, const struct pollfd *,
77 void (*delete_watch)(struct dhcpcd_connection *, const struct pollfd *,
80 void (*event)(struct dhcpcd_connection *, DHCPCD_IF *, void *);
81 void (*status_changed)(struct dhcpcd_connection *, const char *,
83 void (*wi_scanresults)(struct dhcpcd_connection *, DHCPCD_IF *,
86 DHCPCD_IF *interfaces;
87 struct dhcpcd_connection *next;
90 typedef struct dhcpcd_watch {
91 DHCPCD_CONNECTION *connection;
94 struct dhcpcd_watch *next;
96 extern DHCPCD_WATCH *dhcpcd_watching;
98 #define DHCPCD_SERVICE "name.marples.roy.dhcpcd"
99 #define DHCPCD_PATH "/name/marples/roy/dhcpcd"
101 bool dhcpcd_iter_get(DHCPCD_CONNECTION *, DHCPCD_MESSAGEITER *, int, void *);
102 DHCPCD_MESSAGE * dhcpcd_send_reply(DHCPCD_CONNECTION *, DHCPCD_MESSAGE *);
103 DHCPCD_MESSAGE * dhcpcd_message_reply(DHCPCD_CONNECTION *,
104 const char *, const char *);
105 void dhcpcd_error_set(DHCPCD_CONNECTION *, const char *, int);
106 DHCPCD_IF * dhcpcd_if_new(DHCPCD_CONNECTION *, DBusMessageIter *, char **);
107 void dhcpcd_if_free(DHCPCD_IF *);
108 void dhcpcd_dispatch_signal(DHCPCD_CONNECTION *, const char *, void *);
109 bool dhcpcd_dispatch_message(DHCPCD_CONNECTION *, DHCPCD_MESSAGE *);
111 typedef void * DHCPCD_CONNECTION;
114 #define DHCPCD_CALLBACK void (*callback)(DHCPCD_CONNECTION *, void *, void *)
116 DHCPCD_CONNECTION * dhcpcd_open(char **);
117 bool dhcpcd_close(DHCPCD_CONNECTION *);
118 const char * dhcpcd_error(DHCPCD_CONNECTION *);
119 void dhcpcd_error_clear(DHCPCD_CONNECTION *);
120 void dhcpcd_set_watch_functions(DHCPCD_CONNECTION *,
121 void (*)(DHCPCD_CONNECTION *, const struct pollfd *, void *),
122 void (*)(DHCPCD_CONNECTION *, const struct pollfd *, void *),
124 void dhcpcd_set_signal_functions(DHCPCD_CONNECTION *,
125 void (*)(DHCPCD_CONNECTION *, DHCPCD_IF *, void *),
126 void (*)(DHCPCD_CONNECTION *, const char *, void *),
127 void (*)(DHCPCD_CONNECTION *, DHCPCD_IF *, void *),
129 const char * dhcpcd_status(DHCPCD_CONNECTION *);
130 bool dhcpcd_command(DHCPCD_CONNECTION *, const char *, const char *, char **);
131 void dhcpcd_dispatch(int);
132 DHCPCD_IF * dhcpcd_interfaces(DHCPCD_CONNECTION *);
133 DHCPCD_IF * dhcpcd_if_find(DHCPCD_CONNECTION *, const char *);
134 DHCPCD_CONNECTION * dhcpcd_if_connection(DHCPCD_IF *);
136 bool dhcpcd_if_up(const DHCPCD_IF *);
137 bool dhcpcd_if_down(const DHCPCD_IF *);
138 char * dhcpcd_if_message(const DHCPCD_IF *);
140 DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_CONNECTION *, DHCPCD_IF *);
141 void dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *);
142 bool dhcpcd_wpa_command(DHCPCD_CONNECTION *, DHCPCD_IF *, const char *, int);
143 bool dhcpcd_wpa_set_network(DHCPCD_CONNECTION *, DHCPCD_IF *,
144 int, const char *, const char *);
145 int dhcpcd_wpa_find_network_new(DHCPCD_CONNECTION *, DHCPCD_IF *,
148 #define dhcpcd_rebind(c, i) \
149 dhcpcd_command(c, "Rebind", i ? (i)->ifname : NULL, NULL)
150 #define dhcpcd_release(c, i) \
151 dhcpcd_command(c, "Release", i ? (i)->ifname : NULL, NULL)
153 /* Our configuration is probably going to change ... */
155 typedef struct dhcpcd_config {
158 struct dhcpcd_config *next;
161 typedef void *DHCPCD_CONFIG;
164 char ** dhcpcd_config_blocks_get(DHCPCD_CONNECTION *, const char *);
165 DHCPCD_CONFIG * dhcpcd_config_load(DHCPCD_CONNECTION *,
166 const char *, const char *);
167 void dhcpcd_config_free(DHCPCD_CONFIG *);
168 const char * dhcpcd_config_get(DHCPCD_CONFIG *, const char *);
169 const char * dhcpcd_config_get_static(DHCPCD_CONFIG *, const char *);
170 bool dhcpcd_config_set(DHCPCD_CONFIG **, const char *, const char *);
171 bool dhcpcd_config_set_static(DHCPCD_CONFIG **, const char *, const char *);
172 bool dhcpcd_config_save(DHCPCD_CONNECTION *,
173 const char *, const char *, DHCPCD_CONFIG *);