835e8fc7d1dd50f16e82f80105dcc53350b4e062
[platform/core/connectivity/net-config.git] / src / wifi.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <vconf.h>
23 #include <vconf-keys.h>
24
25 #include "log.h"
26 #include "wifi.h"
27 #include "util.h"
28 #include "netdbus.h"
29 #include "neterror.h"
30 #include "netconfig.h"
31 #include "wifi-power.h"
32 #include "wifi-state.h"
33 #include "wifi-ssid-scan.h"
34 #include "wifi-eap.h"
35 #include "wifi-passpoint.h"
36 #include "wifi-eap-config.h"
37 #include "wifi-background-scan.h"
38 #include "wifi-agent.h"
39
40 #include "netconfig-iface-wifi-glue.h"
41
42
43 #define PROP_DEFAULT            FALSE
44 #define PROP_DEFAULT_STR        NULL
45
46 enum {
47         PROP_O,
48         PROP_WIFI_CONN,
49         PROP_WIFI_PATH,
50 };
51
52 enum {
53         SIG_WIFI_DRIVER,
54         SIG_LAST
55 };
56
57 struct NetconfigWifiClass {
58         GObjectClass parent;
59
60         /* method and signals */
61         void (*driver_loaded) (NetconfigWifi *wifi, gchar *mac);
62 };
63
64 struct NetconfigWifi {
65         GObject parent;
66
67         /* member variable */
68         DBusGConnection *conn;
69         gchar *path;
70 };
71
72 static guint32 signals[SIG_LAST] = { 0, };
73
74 G_DEFINE_TYPE(NetconfigWifi, netconfig_wifi, G_TYPE_OBJECT);
75
76
77 static void __netconfig_wifi_gobject_get_property(GObject *object, guint prop_id,
78                 GValue *value, GParamSpec *pspec)
79 {
80         return;
81 }
82
83 static void __netconfig_wifi_gobject_set_property(GObject *object, guint prop_id,
84                 const GValue *value, GParamSpec *pspec)
85 {
86         NetconfigWifi *wifi = NETCONFIG_WIFI(object);
87
88         switch (prop_id) {
89         case PROP_WIFI_CONN:
90         {
91                 wifi->conn = g_value_get_boxed(value);
92                 INFO("wifi(%p) set conn(%p)", wifi, wifi->conn);
93                 break;
94         }
95
96         case PROP_WIFI_PATH:
97         {
98                 if (wifi->path)
99                         g_free(wifi->path);
100
101                 wifi->path = g_value_dup_string(value);
102                 INFO("wifi(%p) path(%s)", wifi, wifi->path);
103
104                 break;
105         }
106
107         default:
108                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
109         }
110 }
111
112 static void netconfig_wifi_init(NetconfigWifi *wifi)
113 {
114         DBG("wifi initialize");
115
116         wifi->conn = NULL;
117         wifi->path = g_strdup(PROP_DEFAULT_STR);
118 }
119
120 static void netconfig_wifi_class_init(NetconfigWifiClass *klass)
121 {
122         GObjectClass *object_class = G_OBJECT_CLASS(klass);
123
124         DBG("class initialize");
125
126         object_class->get_property = __netconfig_wifi_gobject_get_property;
127         object_class->set_property = __netconfig_wifi_gobject_set_property;
128
129         /* DBus register */
130         dbus_g_object_type_install_info(NETCONFIG_TYPE_WIFI,
131                         &dbus_glib_netconfig_iface_wifi_object_info);
132
133         /* property */
134         g_object_class_install_property(object_class, PROP_WIFI_CONN,
135                         g_param_spec_boxed("conn", "CONNECTION", "DBus connection",
136                                 DBUS_TYPE_G_CONNECTION,
137                                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
138
139         g_object_class_install_property(object_class, PROP_WIFI_PATH,
140                         g_param_spec_string("path", "PATH", "Object Path",
141                                 PROP_DEFAULT_STR,
142                                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
143
144         /* signal */
145         signals[SIG_WIFI_DRIVER] = g_signal_new("driver-loaded",
146                         G_OBJECT_CLASS_TYPE(klass),
147                         G_SIGNAL_RUN_LAST,
148                         G_STRUCT_OFFSET(NetconfigWifiClass,
149                                 driver_loaded),
150                         NULL, NULL,
151                         g_cclosure_marshal_VOID__STRING,
152                         G_TYPE_NONE, 1, G_TYPE_STRING);
153 }
154
155 gpointer netconfig_wifi_create_and_init(DBusGConnection *conn)
156 {
157         GObject *object;
158
159         g_return_val_if_fail(conn != NULL, NULL);
160
161         object = g_object_new(NETCONFIG_TYPE_WIFI, "conn", conn, "path",
162                         NETCONFIG_WIFI_PATH, NULL);
163
164         INFO("create wifi(%p)", object);
165
166         dbus_g_connection_register_g_object(conn, NETCONFIG_WIFI_PATH, object);
167
168         INFO("wifi(%p) register DBus path(%s)", object, NETCONFIG_WIFI_PATH);
169
170         netconfig_wifi_power_configuration();
171         netconfig_wifi_init_bgscan();
172
173         return object;
174 }