Increase number of DHCP discover attempts for interoperability
[framework/connectivity/connman.git] / gdhcp / gdhcp.h
1 /*
2  *
3  *  DHCP library with GLib integration
4  *
5  *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef __G_DHCP_H
23 #define __G_DHCP_H
24
25 #include <glib.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /* DHCP Client part*/
32 struct _GDHCPClient;
33
34 typedef struct _GDHCPClient GDHCPClient;
35
36 typedef enum {
37         G_DHCP_CLIENT_ERROR_NONE,
38         G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE,
39         G_DHCP_CLIENT_ERROR_INTERFACE_IN_USE,
40         G_DHCP_CLIENT_ERROR_INTERFACE_DOWN,
41         G_DHCP_CLIENT_ERROR_NOMEM,
42         G_DHCP_CLIENT_ERROR_INVALID_INDEX,
43         G_DHCP_CLIENT_ERROR_INVALID_OPTION
44 } GDHCPClientError;
45
46 typedef enum {
47         G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
48         G_DHCP_CLIENT_EVENT_NO_LEASE,
49         G_DHCP_CLIENT_EVENT_LEASE_LOST,
50         G_DHCP_CLIENT_EVENT_ADDRESS_CONFLICT,
51 } GDHCPClientEvent;
52
53 typedef enum {
54         G_DHCP_IPV4,
55         G_DHCP_IPV6,
56 } GDHCPType;
57
58 #define G_DHCP_SUBNET           0x01
59 #define G_DHCP_ROUTER           0x03
60 #define G_DHCP_TIME_SERVER      0x04
61 #define G_DHCP_DNS_SERVER       0x06
62 #define G_DHCP_DOMAIN_NAME      0x0f
63 #define G_DHCP_HOST_NAME        0x0c
64 #define G_DHCP_NTP_SERVER       0x2a
65
66 typedef void (*GDHCPClientEventFunc) (GDHCPClient *client, gpointer user_data);
67
68 typedef void (*GDHCPDebugFunc)(const char *str, gpointer user_data);
69
70 GDHCPClient *g_dhcp_client_new(GDHCPType type, int index,
71                                                 GDHCPClientError *error);
72
73 int g_dhcp_client_start(GDHCPClient *client);
74 void g_dhcp_client_stop(GDHCPClient *client);
75
76 GDHCPClient *g_dhcp_client_ref(GDHCPClient *client);
77 void g_dhcp_client_unref(GDHCPClient *client);
78
79 void g_dhcp_client_register_event(GDHCPClient *client,
80                                         GDHCPClientEvent event,
81                                         GDHCPClientEventFunc func,
82                                         gpointer user_data);
83
84 GDHCPClientError g_dhcp_client_set_request(GDHCPClient *client,
85                                                 unsigned char option_code);
86 GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client,
87                                                 unsigned char option_code,
88                                                 const char *option_value);
89
90 char *g_dhcp_client_get_address(GDHCPClient *client);
91 GList *g_dhcp_client_get_option(GDHCPClient *client,
92                                                 unsigned char option_code);
93 int g_dhcp_client_get_index(GDHCPClient *client);
94
95 void g_dhcp_client_set_debug(GDHCPClient *client,
96                                 GDHCPDebugFunc func, gpointer user_data);
97
98 /* DHCP Server */
99 typedef enum {
100         G_DHCP_SERVER_ERROR_NONE,
101         G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE,
102         G_DHCP_SERVER_ERROR_INTERFACE_IN_USE,
103         G_DHCP_SERVER_ERROR_INTERFACE_DOWN,
104         G_DHCP_SERVER_ERROR_NOMEM,
105         G_DHCP_SERVER_ERROR_INVALID_INDEX,
106         G_DHCP_SERVER_ERROR_INVALID_OPTION,
107         G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID
108 } GDHCPServerError;
109
110 typedef void (*GDHCPSaveLeaseFunc) (unsigned char *mac,
111                         unsigned int nip, unsigned int expire);
112 struct _GDHCPServer;
113
114 typedef struct _GDHCPServer GDHCPServer;
115
116 GDHCPServer *g_dhcp_server_new(GDHCPType type,
117                 int ifindex, GDHCPServerError *error);
118 int g_dhcp_server_start(GDHCPServer *server);
119 void g_dhcp_server_stop(GDHCPServer *server);
120
121 GDHCPServer *g_dhcp_server_ref(GDHCPServer *server);
122 void g_dhcp_server_unref(GDHCPServer *server);
123
124 int g_dhcp_server_set_option(GDHCPServer *server,
125                 unsigned char option_code, const char *option_value);
126 int g_dhcp_server_set_ip_range(GDHCPServer *server,
127                 const char *start_ip, const char *end_ip);
128 void g_dhcp_server_load_lease(GDHCPServer *dhcp_server, unsigned int expire,
129                                 unsigned char *mac, unsigned int lease_ip);
130 void g_dhcp_server_set_debug(GDHCPServer *server,
131                                 GDHCPDebugFunc func, gpointer user_data);
132 void g_dhcp_server_set_lease_time(GDHCPServer *dhcp_server,
133                                                 unsigned int lease_time);
134 void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
135                                 GDHCPSaveLeaseFunc func, gpointer user_data);
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* __G_DHCP_H */