1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
/*
* libdhcpcd
* Copyright 2009-2015 Roy Marples <roy@marples.name>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef DHCPCD_H
#define DHCPCD_H
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef DHCPCD_SOCKET
#define DHCPCD_SOCKET "/var/run/dhcpcd/sock"
#endif
#ifndef DHCPCD_UNPRIV_SOCKET
#define DHCPCD_UNPRIV_SOCKET "/var/run/dhcpcd/unpriv.sock"
#endif
#ifndef DHCPCD_OSOCKET
#define DHCPCD_OSOCKET "/var/run/dhcpcd.sock"
#endif
#ifndef DHCPCD_UNPRIV_OSOCKET
#define DHCPCD_UNPRIV_OSOCKET "/var/run/dhcpcd.unpriv.sock"
#endif
#ifndef WPA_CTRL_DIR
#define WPA_CTRL_DIR "/var/run/wpa_supplicant"
#endif
#ifndef DHCPCD_TMP_DIR
#define DHCPCD_TMP_DIR "/tmp/dhcpcd"
#endif
#ifndef DHCPCD_TMP_DIR_PERM
#define DHCPCD_TMP_DIR_PERM 0700
#endif
#define DHCPCD_RETRYOPEN 100 /* milliseconds */
#define DHCPCD_WPA_PING 500 /* milliseconds */
#define DHCPCD_WPA_SCAN_LONG 60000 /* milliseconds */
#define DHCPCD_WPA_SCAN_SHORT 5000 /* milliseconds */
#define DHCPCD_WI_HIST_MAX 10 /* Recall 10 scans for averages */
/* Each non printable byte of the SSID is represented as \000 */
#define IF_SSIDSIZE ((32 * 4) + 1)
#define IF_BSSIDSIZE 64
#define FLAGSIZE 64
#define TYPESIZE 8
#define REASONSIZE 16
#define WPA_FREQ_IS_2G(f) ((f) >= 2402 && (f) <= 2472)
#define WPA_FREQ_IS_5G(f) ((f) >= 5170 && (f) <= 5835)
#define DHC_UNKNOWN 0
#define DHC_DOWN 1
#define DHC_OPENED 2
#define DHC_INITIALISED 3
#define DHC_DISCONNECTED 4
#define DHC_CONNECTING 5
#define DHC_AF_WAITING 6
#define DHC_CONNECTED 7
#define DHC_MAX 8
extern const char * const dhcpcd_cstates[];
#define DHT_UNKNOWN 0
#define DHT_LINK 1
#define DHT_DHCP 2
#define DHT_IPV4 2
#define DHT_IPV4LL 3
#define DHT_IPV6 4
#define DHT_RA 5
#define DHT_DHCP6 6
#define DHT_MAX 7
#define DHS_UNKNOWN 0
#define DHS_DUMP 1
#define DHS_TEST 2
#define DHS_STOPPED 3
#define DHS_FAIL 4
#define DHS_STOP 5
#define DHS_PREINIT 6
#define DHS_DEPARTED 7
#define DHS_NOCARRIER 8
#define DHS_NAK 9
#define DHS_EXPIRE 10
#define DHS_RECONFIGURE 11
#define DHS_CARRIER 12
#define DHS_STATIC 13
#define DHS_3RDPARTY 14
#define DHS_IPV4LL 15
#define DHS_INFORM 16
#define DHS_BOUND 17
#define DHS_RENEW 18
#define DHS_REBIND 19
#define DHS_REBOOT 20
#define DHS_ROUTERADVERT 21
#define DHS_DELEGATED 22
#define DHR_MAX 23
typedef struct dhcpcd_wi_avs {
int value;
int average;
} DHCPCD_WI_AV;
typedef struct dhcpcd_wi_scan {
struct dhcpcd_wi_scan *next;
char bssid[IF_BSSIDSIZE];
unsigned int flags;
#define WSF_SECURE 0x001
#define WSF_PSK 0x002
#define WSF_WEP 0x010
#define WSF_WPA 0x020
#define WSF_2G 0x100
#define WSF_5G 0x200
int frequency;
DHCPCD_WI_AV quality;
DHCPCD_WI_AV noise;
DHCPCD_WI_AV level;
DHCPCD_WI_AV strength;
char ssid[IF_SSIDSIZE];
char wpa_flags[FLAGSIZE];
} DHCPCD_WI_SCAN;
#ifdef IN_LIBDHCPCD
typedef struct dhcpcd_if {
struct dhcpcd_if *next;
const char *ifname;
unsigned int type;
unsigned int state;
const char *reason;
unsigned int ifflags;
bool up;
bool wireless;
const char *ssid;
int freq;
char *data;
size_t data_len;
char *last_message;
struct dhcpcd_connection *con;
} DHCPCD_IF;
#else
typedef struct dhcpcd_if {
struct dhcpcd_if *next;
const char *ifname;
unsigned int type;
unsigned int state;
const char *reason;
unsigned int ifflags;
bool up;
bool wireless;
const char *ssid;
int freq;
} DHCPCD_IF;
#endif
typedef struct dhcpcd_config {
struct dhcpcd_config *next;
char *option;
char *value;
} DHCPCD_OPTION;
#ifdef IN_LIBDHCPCD
typedef struct dhcpcd_wi_hist {
struct dhcpcd_wi_hist *next;
char ifname[IF_NAMESIZE];
char bssid[IF_BSSIDSIZE];
int quality;
int noise;
int level;
int strength;
} DHCPCD_WI_HIST;
typedef struct dhcpcd_wpa {
struct dhcpcd_wpa *next;
char ifname[IF_NAMESIZE];
unsigned int status;
int command_fd;
char *command_path;
int listen_fd;
char *listen_path;
bool attached;
struct dhcpcd_connection *con;
} DHCPCD_WPA;
typedef struct dhcpcd_connection {
struct dhcpcd_connection *next;
bool open;
bool privileged;
int command_fd;
int listen_fd;
const char *progname;
DHCPCD_IF *interfaces;
DHCPCD_WPA *wpa;
DHCPCD_WI_HIST *wi_history;
void (*if_cb)(DHCPCD_IF *, void *);
void *if_context;
void (*status_cb)(struct dhcpcd_connection *,
unsigned int, const char *, void *);
void *status_context;
bool wpa_started;
void (*wi_scanresults_cb)(DHCPCD_WPA *, void *);
void *wi_scanresults_context;
void (*wpa_status_cb)(DHCPCD_WPA *, unsigned int, const char *, void *);
void *wpa_status_context;
char *buf;
size_t buflen;
char *version;
bool terminate_commands;
char *error;
int err;
int errors;
unsigned int status;
bool af_waiting;
char *cffile;
} DHCPCD_CONNECTION;
#else
typedef void *DHCPCD_CONFIG;
typedef void *DHCPCD_WPA;
typedef void *DHCPCD_CONNECTION;
#endif
DHCPCD_CONNECTION * dhcpcd_new(void);
const char * dhcpcd_version(DHCPCD_CONNECTION *);
void dhcpcd_set_progname(DHCPCD_CONNECTION *, const char *);
const char * dhcpcd_get_progname(const DHCPCD_CONNECTION *);
unsigned int dhcpcd_status(DHCPCD_CONNECTION *, const char **);
bool dhcpcd_af_waiting(const DHCPCD_CONNECTION *);
const char * dhcpcd_cffile(DHCPCD_CONNECTION *);
bool dhcpcd_realloc(DHCPCD_CONNECTION *, size_t);
int dhcpcd_open(DHCPCD_CONNECTION *, bool priv);
void dhcpcd_close(DHCPCD_CONNECTION *);
void dhcpcd_free(DHCPCD_CONNECTION *);
void dhcpcd_set_if_callback(DHCPCD_CONNECTION *,
void (*)(DHCPCD_IF *, void *), void *);
void dhcpcd_set_status_callback(DHCPCD_CONNECTION *,
void (*)(DHCPCD_CONNECTION *, unsigned int, const char *, void *), void *);
int dhcpcd_get_fd(DHCPCD_CONNECTION *);
bool dhcpcd_privileged(DHCPCD_CONNECTION *);
void dhcpcd_dispatch(DHCPCD_CONNECTION *);
DHCPCD_IF * dhcpcd_interfaces(DHCPCD_CONNECTION *);
char **dhcpcd_interface_names(DHCPCD_CONNECTION *, size_t *);
void dhcpcd_freev(char **);
char **dhcpcd_interface_names_sorted(DHCPCD_CONNECTION *);
DHCPCD_IF * dhcpcd_get_if(DHCPCD_CONNECTION *, const char *, unsigned int);
DHCPCD_CONNECTION * dhcpcd_if_connection(DHCPCD_IF *);
const char *dhcpcd_get_value(const DHCPCD_IF *, const char *);
const char *dhcpcd_get_prefix_value(const DHCPCD_IF *, const char *,
const char *);
ssize_t dhcpcd_encode_string_escape(char *, size_t, const char *, size_t);
ssize_t dhcpcd_decode_string_escape(char *, size_t, const char *);
ssize_t dhcpcd_decode_hex(char *, size_t, const char *);
char * dhcpcd_if_message(DHCPCD_IF *, bool *);
ssize_t dhcpcd_command(DHCPCD_CONNECTION *, const char *, char **);
ssize_t dhcpcd_command_arg(DHCPCD_CONNECTION *, const char *, const char *,
char **);
#define dhcpcd_rebind(c, i) dhcpcd_command_arg((c), "-n", (i), NULL)
#define dhcpcd_release(c, i) dhcpcd_command_arg((c), "-k", (i), NULL)
void dhcpcd_wpa_start(DHCPCD_CONNECTION *);
DHCPCD_WPA *dhcpcd_wpa_find(DHCPCD_CONNECTION *, const char *);
DHCPCD_WPA *dhcpcd_wpa_new(DHCPCD_CONNECTION *, const char *);
DHCPCD_CONNECTION *dhcpcd_wpa_connection(DHCPCD_WPA *);
int dhcpcd_wpa_open(DHCPCD_WPA *);
void dhcpcd_wpa_close(DHCPCD_WPA *);
void dhcpcd_wpa_dispatch(DHCPCD_WPA *);
int dhcpcd_wpa_get_fd(DHCPCD_WPA *);
DHCPCD_IF *dhcpcd_wpa_if(DHCPCD_WPA *);
void dhcpcd_wpa_if_event(DHCPCD_IF *);
void dhcpcd_wpa_set_scan_callback(DHCPCD_CONNECTION *,
void (*)(DHCPCD_WPA *, void *), void *);
void dhcpcd_wpa_set_status_callback(DHCPCD_CONNECTION *,
void (*)(DHCPCD_WPA *, unsigned int, const char *, void *), void *);
int dhcpcd_wi_scan_compare(DHCPCD_WI_SCAN *a, DHCPCD_WI_SCAN *b);
DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_IF *);
bool dhcpcd_wi_associated(DHCPCD_IF *i, DHCPCD_WI_SCAN *s);
void dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *);
void dhcpcd_wi_history_clear(DHCPCD_CONNECTION *);
bool dhcpcd_wpa_set_network(DHCPCD_WPA *, int, const char *, const char *);
int dhcpcd_wpa_find_network_new(DHCPCD_WPA *, const char *);
bool dhcpcd_wpa_command(DHCPCD_WPA *, const char *);
bool dhcpcd_wpa_command_arg(DHCPCD_WPA *, const char *, const char *);
unsigned int dhcpcd_wpa_status(DHCPCD_WPA *, const char **);
int dhcpcd_wpa_freq(DHCPCD_WPA *);
#define WST_BSSID 0x01
#define WST_FLAGS 0x02
#define WST_FREQ 0x03
int dhcpcd_wi_print_tooltip(char *, size_t, DHCPCD_WI_SCAN *, unsigned int);
bool dhcpcd_wpa_ping(DHCPCD_WPA *);
bool dhcpcd_wpa_can_background_scan(DHCPCD_WPA *);
bool dhcpcd_wpa_scan(DHCPCD_WPA *);
bool dhcpcd_wpa_reconfigure(DHCPCD_WPA *);
bool dhcpcd_wpa_reassociate(DHCPCD_WPA *);
bool dhcpcd_wpa_disconnect(DHCPCD_WPA *);
bool dhcpcd_wpa_config_write(DHCPCD_WPA *);
int dhcpcd_wpa_network_find_new(DHCPCD_WPA *, const char *);
bool dhcpcd_wpa_network_disable(DHCPCD_WPA *, int);
bool dhcpcd_wpa_network_enable(DHCPCD_WPA *, int);
bool dhcpcd_wpa_network_select(DHCPCD_WPA *, int);
bool dhcpcd_wpa_network_remove(DHCPCD_WPA *, int);
char * dhcpcd_wpa_network_get(DHCPCD_WPA *, int, const char *);
bool dhcpcd_wpa_network_set(DHCPCD_WPA *, int, const char *, const char *);
#define DHCPCD_WPA_SUCCESS 0
#define DHCPCD_WPA_ERR -1
#define DHCPCD_WPA_ERR_SET -2
#define DHCPCD_WPA_ERR_SET_PSK -3
#define DHCPCD_WPA_ERR_ENABLE -4
#define DHCPCD_WPA_ERR_WRITE -5
#define DHCPCD_WPA_ERR_SELECT -6
#define DHCPCD_WPA_ERR_ASSOC -7
#define DHCPCD_WPA_ERR_DISCONN -8
#define DHCPCD_WPA_ERR_RECONF -9
int dhcpcd_wpa_configure(DHCPCD_WPA *w, DHCPCD_WI_SCAN *s, const char *p);
int dhcpcd_wpa_select(DHCPCD_WPA *w, DHCPCD_WI_SCAN *s);
char ** dhcpcd_config_blocks(DHCPCD_CONNECTION *, const char *);
DHCPCD_OPTION *dhcpcd_config_read(DHCPCD_CONNECTION *,
const char *, const char *);
void dhcpcd_config_free(DHCPCD_OPTION *);
const char * dhcpcd_config_get(DHCPCD_OPTION *, const char *);
const char * dhcpcd_config_get_static(DHCPCD_OPTION *, const char *);
bool dhcpcd_config_set(DHCPCD_OPTION **, const char *, const char *);
bool dhcpcd_config_set_static(DHCPCD_OPTION **, const char *, const char *);
bool dhcpcd_config_writeable(DHCPCD_CONNECTION *con);
bool dhcpcd_config_write(DHCPCD_CONNECTION *,
const char *, const char *, const DHCPCD_OPTION *);
#ifdef __cplusplus
}
#endif
#endif
|