7c770d9550f357182b96c10c0fb32ad062b46bd4
[platform/core/connectivity/wifi-direct-manager.git] / prd / plugin / wpasupplicant / ctrl_iface_sock / wfd-prd-plugin-wpasupplicant.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2016 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 <glib.h>
21
22 #include "wifi-direct-oem.h"
23 #include "wfd-prd-plugin-log.h"
24 #include "wfd-prd-plugin-wpasupplicant.h"
25
26 static ws_sock_plugin_data_s *g_pd;
27
28 static int _ws_reset_plugin(ws_sock_plugin_data_s *pd)
29 {
30         __WDP_LOG_FUNC_ENTER__;
31
32         if (!pd) {
33                 WDP_LOGE("Invalid parameter");
34                 __WDP_LOG_FUNC_EXIT__;
35                 return -1;
36         }
37
38         g_free(pd);
39
40         __WDP_LOG_FUNC_EXIT__;
41         return 0;
42 }
43
44 int ws_prd_init(wfd_oem_event_cbs_s *event_cbs)
45 {
46         __WDP_LOG_FUNC_ENTER__;
47
48         if (event_cbs == NULL) {
49                 __WDP_LOG_FUNC_EXIT__;
50                 return -1;
51         }
52
53         if (g_pd)
54                 _ws_reset_plugin(g_pd);
55
56         errno = 0;
57         g_pd = (ws_sock_plugin_data_s*) g_try_malloc0(sizeof(ws_sock_plugin_data_s));
58         if (!g_pd) {
59                 WDP_LOGE("Failed to allocate memory for plugin data. [%s]",
60                          strerror(errno));
61                 __WDP_LOG_FUNC_EXIT__;
62                 return -1;
63         }
64
65         g_pd->callback = event_cbs;
66         g_pd->initialized = TRUE;
67
68         __WDP_LOG_FUNC_EXIT__;
69         return 0;
70 }
71
72 wfd_oem_prd_ops_s prd_ops = {
73         .prd_init = ws_prd_init,
74 };
75
76 int wfd_prd_plugin_load(wfd_oem_ops_s **ops)
77 {
78         __WDP_LOG_FUNC_ENTER__;
79
80         if (!ops) {
81                 WDP_LOGE("Invalid parameter");
82                 __WDP_LOG_FUNC_EXIT__;
83                 return -1;
84         }
85
86         (*ops)->extra_data = &prd_ops;
87
88         __WDP_LOG_FUNC_EXIT__;
89         return 0;
90 }