Create element for every network in range
[connman] / include / element.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  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_ELEMENT_H
23 #define __CONNMAN_ELEMENT_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <errno.h>
30 #include <glib.h>
31
32 #include <connman/property.h>
33
34 enum connman_element_state {
35         CONNMAN_ELEMENT_STATE_UNKNOWN   = 0,
36         CONNMAN_ELEMENT_STATE_CONNECT   = 1,
37         CONNMAN_ELEMENT_STATE_CONNECTED = 2,
38         CONNMAN_ELEMENT_STATE_CLOSED    = 3,
39 };
40
41 enum connman_element_type {
42         CONNMAN_ELEMENT_TYPE_UNKNOWN    = 0,
43         CONNMAN_ELEMENT_TYPE_ROOT       = 1,
44         CONNMAN_ELEMENT_TYPE_DEVICE     = 2,
45         CONNMAN_ELEMENT_TYPE_NETWORK    = 3,
46         CONNMAN_ELEMENT_TYPE_IPV4       = 4,
47         CONNMAN_ELEMENT_TYPE_IPV6       = 5,
48         CONNMAN_ELEMENT_TYPE_DHCP       = 6,
49         CONNMAN_ELEMENT_TYPE_BOOTP      = 7,
50         CONNMAN_ELEMENT_TYPE_ZEROCONF   = 8,
51         CONNMAN_ELEMENT_TYPE_RESOLVER   = 9,
52
53         CONNMAN_ELEMENT_TYPE_CONNECTION = 42,
54 };
55
56 enum connman_element_subtype {
57         CONNMAN_ELEMENT_SUBTYPE_UNKNOWN   = 0,
58         CONNMAN_ELEMENT_SUBTYPE_ETHERNET  = 1,
59         CONNMAN_ELEMENT_SUBTYPE_WIFI      = 2,
60         CONNMAN_ELEMENT_SUBTYPE_WIMAX     = 3,
61         CONNMAN_ELEMENT_SUBTYPE_MODEM     = 4,
62         CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH = 5,
63 };
64
65 struct connman_driver;
66
67 struct connman_element {
68         gint refcount;
69         GStaticMutex mutex;
70         gchar *name;
71         gchar *path;
72         enum connman_element_type type;
73         enum connman_element_subtype subtype;
74         enum connman_element_state state;
75         guint16 priority;
76
77         struct connman_element *parent;
78
79         struct connman_driver *driver;
80         void *driver_data;
81
82         GSList *properties;
83
84         struct {
85                 int index;
86                 short flags;
87                 gchar *name;
88         } netdev;
89
90         struct {
91                 gchar *identifier;
92         } network;
93
94         struct {
95                 gchar *address;
96                 gchar *netmask;
97                 gchar *gateway;
98                 gchar *network;
99                 gchar *broadcast;
100                 gchar *nameserver;
101         } ipv4;
102 };
103
104 #define connman_element_lock(element)    g_static_mutex_lock(&(element)->mutex)
105 #define connman_element_unlock(element)  g_static_mutex_unlock(&(element)->mutex)
106
107 extern struct connman_element *connman_element_create(void);
108 extern struct connman_element *connman_element_ref(struct connman_element *element);
109 extern void connman_element_unref(struct connman_element *element);
110
111 extern int connman_element_add_static_property(struct connman_element *element,
112                                 const char *name, int type, const void *value);
113 extern int connman_element_set_property(struct connman_element *element,
114                         enum connman_property_type type, const void *value);
115 extern int connman_element_get_value(struct connman_element *element,
116                                 enum connman_property_type type, void *value);
117
118 extern int connman_element_register(struct connman_element *element,
119                                         struct connman_element *parent);
120 extern void connman_element_unregister(struct connman_element *element);
121 extern void connman_element_update(struct connman_element *element);
122
123 static inline void *connman_element_get_data(struct connman_element *element)
124 {
125         return element->driver_data;
126 }
127
128 static inline void connman_element_set_data(struct connman_element *element,
129                                                                 void *data)
130 {
131         element->driver_data = data;
132 }
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif /* __CONNMAN_ELEMENT_H */