3 * Copyright 2009-2014 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
42 typedef struct dhcpcd_wi_avs {
47 typedef struct dhcpcd_wi_scan {
48 struct dhcpcd_wi_scan *next;
49 char bssid[IF_BSSIDSIZE];
54 char ssid[IF_SSIDSIZE];
58 typedef struct dhcpcd_if {
59 struct dhcpcd_if *next;
60 char ifname[IF_NAMESIZE];
64 char ssid[IF_SSIDSIZE];
66 char reason[REASONSIZE];
68 struct in6_addr prefix;
74 /* Although we use DBus, we don't have to rely on it for our API */
76 #include <dbus/dbus.h>
77 typedef DBusMessage DHCPCD_MESSAGE;
78 typedef DBusMessageIter DHCPCD_MESSAGEITER;
80 typedef struct dhcpcd_wi_hist {
81 struct dhcpcd_wi_hist *next;
82 char ifname[IF_NAMESIZE];
83 char bssid[IF_BSSIDSIZE];
89 typedef struct dhcpcd_connection {
90 struct dhcpcd_connection *next;
96 void (*add_watch)(struct dhcpcd_connection *, const struct pollfd *,
98 void (*delete_watch)(struct dhcpcd_connection *, const struct pollfd *,
101 void (*event)(struct dhcpcd_connection *, DHCPCD_IF *, void *);
102 void (*status_changed)(struct dhcpcd_connection *, const char *,
104 void (*wi_scanresults)(struct dhcpcd_connection *, DHCPCD_IF *,
107 DHCPCD_IF *interfaces;
108 DHCPCD_WI_HIST *wi_history;
111 typedef struct dhcpcd_watch {
112 struct dhcpcd_watch *next;
113 DHCPCD_CONNECTION *connection;
115 struct pollfd pollfd;
117 extern DHCPCD_WATCH *dhcpcd_watching;
119 #define DHCPCD_SERVICE "name.marples.roy.dhcpcd"
120 #define DHCPCD_PATH "/name/marples/roy/dhcpcd"
122 bool dhcpcd_iter_get(DHCPCD_CONNECTION *, DHCPCD_MESSAGEITER *, int, void *);
123 DHCPCD_MESSAGE * dhcpcd_send_reply(DHCPCD_CONNECTION *, DHCPCD_MESSAGE *);
124 DHCPCD_MESSAGE * dhcpcd_message_reply(DHCPCD_CONNECTION *,
125 const char *, const char *);
126 void dhcpcd_error_set(DHCPCD_CONNECTION *, const char *, int);
127 DHCPCD_IF * dhcpcd_if_new(DHCPCD_CONNECTION *, DBusMessageIter *, char **);
128 void dhcpcd_if_free(DHCPCD_IF *);
129 void dhcpcd_dispatch_signal(DHCPCD_CONNECTION *, const char *, void *);
130 bool dhcpcd_dispatch_message(DHCPCD_CONNECTION *, DHCPCD_MESSAGE *);
132 typedef void * DHCPCD_CONNECTION;
135 DHCPCD_CONNECTION * dhcpcd_open(char **);
136 bool dhcpcd_close(DHCPCD_CONNECTION *);
137 const char * dhcpcd_error(DHCPCD_CONNECTION *);
138 void dhcpcd_error_clear(DHCPCD_CONNECTION *);
139 void dhcpcd_set_watch_functions(DHCPCD_CONNECTION *,
140 void (*)(DHCPCD_CONNECTION *, const struct pollfd *, void *),
141 void (*)(DHCPCD_CONNECTION *, const struct pollfd *, void *),
143 void dhcpcd_set_signal_functions(DHCPCD_CONNECTION *,
144 void (*)(DHCPCD_CONNECTION *, DHCPCD_IF *, void *),
145 void (*)(DHCPCD_CONNECTION *, const char *, void *),
146 void (*)(DHCPCD_CONNECTION *, DHCPCD_IF *, void *),
148 const char * dhcpcd_status(DHCPCD_CONNECTION *);
149 bool dhcpcd_command(DHCPCD_CONNECTION *, const char *, const char *, char **);
150 void dhcpcd_dispatch(int);
151 DHCPCD_IF * dhcpcd_interfaces(DHCPCD_CONNECTION *);
152 DHCPCD_IF * dhcpcd_if_find(DHCPCD_CONNECTION *, const char *, const char *);
153 DHCPCD_CONNECTION * dhcpcd_if_connection(DHCPCD_IF *);
155 char * dhcpcd_if_message(const DHCPCD_IF *);
157 DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_CONNECTION *, DHCPCD_IF *);
158 void dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *);
159 void dhcpcd_wi_history_clear(DHCPCD_CONNECTION *);
160 bool dhcpcd_wpa_command(DHCPCD_CONNECTION *, DHCPCD_IF *, const char *, int);
161 bool dhcpcd_wpa_set_network(DHCPCD_CONNECTION *, DHCPCD_IF *,
162 int, const char *, const char *);
163 int dhcpcd_wpa_find_network_new(DHCPCD_CONNECTION *, DHCPCD_IF *,
166 #define dhcpcd_rebind(c, i) \
167 dhcpcd_command(c, "Rebind", i ? (i)->ifname : NULL, NULL)
168 #define dhcpcd_release(c, i) \
169 dhcpcd_command(c, "Release", i ? (i)->ifname : NULL, NULL)
171 /* Our configuration is probably going to change ... */
173 typedef struct dhcpcd_config {
176 struct dhcpcd_config *next;
179 typedef void *DHCPCD_CONFIG;
182 char ** dhcpcd_config_blocks_get(DHCPCD_CONNECTION *, const char *);
183 DHCPCD_CONFIG * dhcpcd_config_load(DHCPCD_CONNECTION *,
184 const char *, const char *);
185 void dhcpcd_config_free(DHCPCD_CONFIG *);
186 const char * dhcpcd_config_get(DHCPCD_CONFIG *, const char *);
187 const char * dhcpcd_config_get_static(DHCPCD_CONFIG *, const char *);
188 bool dhcpcd_config_set(DHCPCD_CONFIG **, const char *, const char *);
189 bool dhcpcd_config_set_static(DHCPCD_CONFIG **, const char *, const char *);
190 bool dhcpcd_config_save(DHCPCD_CONNECTION *,
191 const char *, const char *, DHCPCD_CONFIG *);