Add support for creating and removing networks
[connman] / include / iface.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007  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 __CONNMAN_IFACE_H
23 #define __CONNMAN_IFACE_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <netinet/in.h>
30
31 enum connman_iface_type {
32         CONNMAN_IFACE_TYPE_UNKNOWN   = 0,
33         CONNMAN_IFACE_TYPE_80203     = 1,
34         CONNMAN_IFACE_TYPE_80211     = 2,
35         CONNMAN_IFACE_TYPE_WIMAX     = 3,
36         CONNMAN_IFACE_TYPE_MODEM     = 4,
37         CONNMAN_IFACE_TYPE_BLUETOOTH = 5,
38 };
39
40 enum connman_iface_flags {
41         CONNMAN_IFACE_FLAG_RTNL      = (1 << 0),
42         CONNMAN_IFACE_FLAG_IPV4      = (1 << 1),
43         CONNMAN_IFACE_FLAG_IPV6      = (1 << 2),
44         CONNMAN_IFACE_FLAG_SCANNING  = (1 << 3),
45         CONNMAN_IFACE_FLAG_NOCARRIER = (1 << 4),
46
47         CONNMAN_IFACE_FLAG_STARTED   = (1 << 16),
48         CONNMAN_IFACE_FLAG_RUNNING   = (1 << 17),
49         CONNMAN_IFACE_FLAG_DHCP      = (1 << 18),
50 };
51
52 enum connman_iface_state {
53         CONNMAN_IFACE_STATE_UNKNOWN   = 0,
54         CONNMAN_IFACE_STATE_OFF       = 1,
55         CONNMAN_IFACE_STATE_ENABLED   = 2,
56         CONNMAN_IFACE_STATE_SCANNING  = 3,
57         CONNMAN_IFACE_STATE_CONNECT   = 4,
58         CONNMAN_IFACE_STATE_CONNECTED = 5,
59         CONNMAN_IFACE_STATE_CARRIER   = 6,
60         CONNMAN_IFACE_STATE_CONFIGURE = 7,
61         CONNMAN_IFACE_STATE_READY     = 8,
62         CONNMAN_IFACE_STATE_SHUTDOWN  = 9,
63 };
64
65 enum connman_iface_policy {
66         CONNMAN_IFACE_POLICY_UNKNOWN = 0,
67         CONNMAN_IFACE_POLICY_OFF     = 1,
68         CONNMAN_IFACE_POLICY_IGNORE  = 2,
69         CONNMAN_IFACE_POLICY_AUTO    = 3,
70         CONNMAN_IFACE_POLICY_ASK     = 4,
71 };
72
73 enum connman_ipv4_method {
74         CONNMAN_IPV4_METHOD_UNKNOWN = 0,
75         CONNMAN_IPV4_METHOD_OFF     = 1,
76         CONNMAN_IPV4_METHOD_STATIC  = 2,
77         CONNMAN_IPV4_METHOD_DHCP    = 3,
78 };
79
80 struct connman_ipv4 {
81         enum connman_ipv4_method method;
82         struct in_addr address;
83         struct in_addr netmask;
84         struct in_addr gateway;
85         struct in_addr network;
86         struct in_addr broadcast;
87         struct in_addr nameserver;
88 };
89
90 struct connman_network {
91         struct connman_iface *iface;
92         char *path;
93         char *identifier;
94         char *passphrase;
95 };
96
97 struct connman_iface {
98         char *path;
99         char *udi;
100         char *sysfs;
101         char *identifier;
102         int index;
103         enum connman_iface_type type;
104         unsigned long flags;
105         enum connman_iface_state state;
106         enum connman_iface_policy policy;
107         struct connman_network network;
108         struct connman_ipv4 ipv4;
109
110         struct connman_iface_driver *driver;
111         void *driver_data;
112
113         void *rtnl_data;
114
115         struct {
116                 char *driver;
117                 char *vendor;
118                 char *product;
119         } device;
120 };
121
122 struct connman_iface_driver {
123         const char *name;
124         const char *capability;
125
126         int (*probe) (struct connman_iface *iface);
127         void (*remove) (struct connman_iface *iface);
128
129         int (*start) (struct connman_iface *iface);
130         int (*stop) (struct connman_iface *iface);
131
132         int (*scan) (struct connman_iface *iface);
133         int (*connect) (struct connman_iface *iface,
134                                         struct connman_network *network);
135         int (*disconnect) (struct connman_iface *iface);
136
137         void (*rtnl_carrier) (struct connman_iface *iface, int carrier);
138         void (*rtnl_wireless) (struct connman_iface *iface,
139                                         void *data, unsigned short len);
140 };
141
142 extern int connman_iface_register(struct connman_iface_driver *driver);
143 extern void connman_iface_unregister(struct connman_iface_driver *driver);
144
145 static inline void *connman_iface_get_data(struct connman_iface *iface)
146 {
147         return iface->driver_data;
148 }
149
150 static inline void connman_iface_set_data(struct connman_iface *iface,
151                                                                 void *data)
152 {
153         iface->driver_data = data;
154 }
155
156 extern void connman_iface_indicate_ifup(struct connman_iface *iface);
157 extern void connman_iface_indicate_ifdown(struct connman_iface *iface);
158 extern void connman_iface_indicate_connected(struct connman_iface *iface);
159 extern void connman_iface_indicate_carrier_on(struct connman_iface *iface);
160 extern void connman_iface_indicate_carrier_off(struct connman_iface *iface);
161 extern void connman_iface_indicate_configured(struct connman_iface *iface);
162
163 extern void connman_iface_indicate_station(struct connman_iface *iface,
164                                 const char *name, int strength, int security);
165
166 extern int connman_iface_get_ipv4(struct connman_iface *iface,
167                                                 struct connman_ipv4 *ipv4);
168 extern int connman_iface_set_ipv4(struct connman_iface *iface,
169                                                 struct connman_ipv4 *ipv4);
170 extern int connman_iface_clear_ipv4(struct connman_iface *iface);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif /* __CONNMAN_IFACE_H */