Add interface index and state variables
[framework/connectivity/connman.git] / plugins / 80211.c
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 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <arpa/inet.h>
28
29 #include <connman/plugin.h>
30 #include <connman/iface.h>
31
32 #include "net.h"
33
34 static int iface_probe(struct connman_iface *iface)
35 {
36         printf("[802.11] probe interface index %d\n", iface->index);
37
38         iface->type = CONNMAN_IFACE_TYPE_80211;
39
40         iface->flags = CONNMAN_IFACE_FLAG_RTNL |
41                                 CONNMAN_IFACE_FLAG_IPV4;
42
43         return 0;
44 }
45
46 static void iface_remove(struct connman_iface *iface)
47 {
48         printf("[802.11] remove interface index %d\n", iface->index);
49
50         __net_clear(iface->index);
51 }
52
53 static int iface_activate(struct connman_iface *iface)
54 {
55         printf("[802.11] activate interface index %d\n", iface->index);
56
57         connman_iface_update(iface, CONNMAN_IFACE_STATE_ACTIVE);
58
59         return 0;
60 }
61
62 static int iface_get_ipv4(struct connman_iface *iface,
63                                         struct connman_ipv4 *ipv4)
64 {
65         if (__net_ifaddr(iface->index, &ipv4->address) < 0)
66                 return -1;
67
68         printf("[802.11] get address %s\n", inet_ntoa(ipv4->address));
69
70         return 0;
71 }
72
73 static int iface_set_ipv4(struct connman_iface *iface,
74                                         struct connman_ipv4 *ipv4)
75 {
76         printf("[802.11] set address %s\n", inet_ntoa(ipv4->address));
77         printf("[802.11] set netmask %s\n", inet_ntoa(ipv4->netmask));
78         printf("[802.11] set gateway %s\n", inet_ntoa(ipv4->gateway));
79
80         __net_set(iface->index, &ipv4->address, &ipv4->netmask,
81                                 &ipv4->gateway, &ipv4->broadcast,
82                                                 &ipv4->nameserver);
83
84         return 0;
85 }
86
87 static int iface_scan(struct connman_iface *iface)
88 {
89         printf("[802.11] scanning interface index %d\n", iface->index);
90
91         return 0;
92 }
93
94 static int iface_connect(struct connman_iface *iface,
95                                         struct connman_network *network)
96 {
97         printf("[802.11] connect interface index %d\n", iface->index);
98
99         return 0;
100 }
101
102 static struct connman_iface_driver iface_driver = {
103         .name           = "80211",
104         .capability     = "net.80211",
105         .probe          = iface_probe,
106         .remove         = iface_remove,
107         .activate       = iface_activate,
108         .get_ipv4       = iface_get_ipv4,
109         .set_ipv4       = iface_set_ipv4,
110         .scan           = iface_scan,
111         .connect        = iface_connect,
112 };
113
114 static int plugin_init(void)
115 {
116         connman_iface_register(&iface_driver);
117
118         return 0;
119 }
120
121 static void plugin_exit(void)
122 {
123         connman_iface_unregister(&iface_driver);
124 }
125
126 CONNMAN_PLUGIN_DEFINE("80211", "IEEE 802.11 interface plugin", VERSION,
127                                                 plugin_init, plugin_exit)