Use rand_r() instead of rand()
[platform/core/connectivity/net-config.git] / src / wifi-extension.c
1 /*
2  * Network Extension Module
3  *
4  * Copyright (c) 2000 - 2012 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 <stdlib.h>
22 #include <unistd.h>
23 #include <errno.h>
24 #include <vconf.h>
25 #include <vconf-keys.h>
26
27 #include "log.h"
28 #include "util.h"
29 #include "neterror.h"
30 #include "netdbus.h"
31 #include "netsupplicant.h"
32 #include "wifi-state.h"
33 #include "wifi-extension.h"
34
35
36 gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context,
37                 const gchar *ifname)
38 {
39         DBG("Wi-Fi flush bss");
40
41         g_return_val_if_fail(wifi != NULL, TRUE);
42
43         GDBusConnection *connection = NULL;
44         char *if_path = NULL;
45
46         if_path = netconfig_wifi_get_supplicant_interface_path(ifname);
47         if (if_path == NULL) {
48                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailFlushBss");
49                 DBG("Fail to get wpa_supplicant DBus path");
50                 return TRUE;
51         }
52
53         connection = netdbus_get_connection();
54         if (connection == NULL) {
55                 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailFlushBss");
56                 ERR("Failed to get netdbus connection");
57                 g_free(if_path);
58                 return TRUE;
59         }
60
61
62         g_dbus_connection_call(connection,
63                         SUPPLICANT_SERVICE,
64                         if_path,
65                         SUPPLICANT_INTERFACE ".Interface",
66                         "FlushBSS",
67                         g_variant_new("(u)", 0),
68                         NULL,
69                         G_DBUS_CALL_FLAGS_NONE,
70                         10 * 1000,
71                         netdbus_get_cancellable(),
72                         NULL,
73                         NULL);
74
75         g_free(if_path);
76         wifi_complete_flush_bss(wifi, context);
77         return TRUE;
78 }