Merge "Added support to set and get IP configuration details." into tizen
[platform/core/connectivity/net-config.git] / gtest / wifi.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <iostream>
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include <stdint.h>
23 #include <glib.h>
24
25 #include "wifi.h"
26
27 Wifi::Wifi()
28 {
29         Create();
30 }
31
32 Wifi::~Wifi()
33 {
34         Destroy();
35 }
36
37 error_e Wifi::GetWifiState(char *state)
38 {
39         GVariant *message = NULL;
40         error_e error = ERROR_NONE;
41
42         message = InvokeMethod(NETCONFIG_SERVICE,
43                 NETCONFIG_WIFI_PATH,
44                 NETCONFIG_WIFI_INTERFACE,
45                 GET_WIFI_STATE,
46                 NULL,
47                 &error);
48
49         if (message == NULL) {
50                 GLOGD("Failed to invoke dbus method");
51                 return error;
52         }
53
54         g_variant_get(message, "(s)", state);
55         g_variant_unref(message);
56
57         return ERROR_NONE;
58 }
59
60 error_e Wifi::IsIpConflictDetectEnabled(gboolean *state)
61 {
62         GVariant *message = NULL;
63         error_e error = ERROR_NONE;
64
65         message = InvokeMethod(NETCONFIG_SERVICE,
66                 NETCONFIG_WIFI_PATH,
67                 NETCONFIG_WIFI_INTERFACE,
68                 IS_IP_CONFLICT_DETECT_ENABLED,
69                 NULL,
70                 &error);
71
72         if (message == NULL) {
73                 GLOGD("Failed to invoke dbus method");
74                 return error;
75         }
76
77         g_variant_get(message, "(b)", state);
78         g_variant_unref(message);
79
80         return ERROR_NONE;
81 }
82
83 error_e Wifi::SetBgscan(int scan_mode)
84 {
85         GVariant *message = NULL;
86         error_e error = ERROR_NONE;
87
88         message = InvokeMethod(NETCONFIG_SERVICE,
89                 NETCONFIG_WIFI_PATH,
90                 NETCONFIG_WIFI_INTERFACE,
91                 SET_BGSCAN,
92                 g_variant_new("(u)", scan_mode),
93                 &error);
94
95         if (message == NULL) {
96                 GLOGD("Failed to invoke dbus method");
97                 return error;
98         }
99
100         g_variant_unref(message);
101
102         return ERROR_NONE;
103 }
104
105 error_e Wifi::GetAutoscan(gboolean *state)
106 {
107         GVariant *message = NULL;
108         error_e error = ERROR_NONE;
109
110         message = InvokeMethod(NETCONFIG_SERVICE,
111                 NETCONFIG_WIFI_PATH,
112                 NETCONFIG_WIFI_INTERFACE,
113                 GET_AUTOSCAN,
114                 NULL,
115                 &error);
116
117         if (message == NULL) {
118                 GLOGD("Failed to invoke dbus method");
119                 return error;
120         }
121
122         g_variant_get(message, "(b)", state);
123         g_variant_unref(message);
124
125         return ERROR_NONE;
126 }
127
128 error_e Wifi::GetIpConflictState(int *state)
129 {
130         GVariant *message = NULL;
131         error_e error = ERROR_NONE;
132
133         message = InvokeMethod(NETCONFIG_SERVICE,
134                 NETCONFIG_WIFI_PATH,
135                 NETCONFIG_WIFI_INTERFACE,
136                 GET_IP_CONFLICT_STATE,
137                 NULL,
138                 &error);
139
140         if (message == NULL) {
141                 GLOGD("Failed to invoke dbus method");
142                 return error;
143         }
144
145         g_variant_get(message, "(u)", state);
146         g_variant_unref(message);
147
148         return ERROR_NONE;
149 }
150
151 error_e Wifi::GetIpConflictPeriod(int *period)
152 {
153         GVariant *message = NULL;
154         error_e error = ERROR_NONE;
155
156         message = InvokeMethod(NETCONFIG_SERVICE,
157                 NETCONFIG_WIFI_PATH,
158                 NETCONFIG_WIFI_INTERFACE,
159                 GET_IP_CONFLICT_PERIOD,
160                 NULL,
161                 &error);
162
163         if (message == NULL) {
164                 GLOGD("Failed to invoke dbus method");
165                 return error;
166         }
167
168         g_variant_get(message, "(u)", period);
169         g_variant_unref(message);
170
171         return ERROR_NONE;
172 }
173
174 error_e Wifi::GetAutoscanmode(int *autoscanmode)
175 {
176         GVariant *message = NULL;
177         error_e error = ERROR_NONE;
178
179         message = InvokeMethod(NETCONFIG_SERVICE,
180                 NETCONFIG_WIFI_PATH,
181                 NETCONFIG_WIFI_INTERFACE,
182                 GET_AUTOSCANMODE,
183                 NULL,
184                 &error);
185
186         if (message == NULL) {
187                 GLOGD("Failed to invoke dbus method");
188                 return error;
189         }
190
191         g_variant_get(message, "(u)", autoscanmode);
192         g_variant_unref(message);
193
194         return ERROR_NONE;
195 }
196
197 error_e Wifi::NetlinkScan(const char *ssid)
198 {
199         GVariant *message = NULL;
200         error_e error = ERROR_NONE;
201         GVariantBuilder *builder;
202         GVariant *params = NULL;
203
204         if (ssid[0] == '\0')
205                 return ERROR_INVALID_PARAMETER;
206
207         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
208         g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid));
209
210         params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
211         g_variant_builder_unref(builder);
212
213         message = InvokeMethod(NETCONFIG_SERVICE,
214                 NETCONFIG_WIFI_PATH,
215                 NETCONFIG_WIFI_INTERFACE,
216                 NETLINK_SCAN,
217                 params,
218                 &error);
219
220         if (message == NULL) {
221                 GLOGD("Failed to invoke dbus method");
222                 return error;
223         }
224
225         g_variant_unref(message);
226
227         return ERROR_NONE;
228 }
229
230 error_e Wifi::RequestWpsConnect(const char *param)
231 {
232         GVariant *message = NULL;
233         error_e error = ERROR_NONE;
234
235         message = InvokeMethod(NETCONFIG_SERVICE,
236                 NETCONFIG_WIFI_PATH,
237                 NETCONFIG_WIFI_INTERFACE,
238                 REQUEST_WPS_CONNECT,
239                 g_variant_new("(s)", param),
240                 &error);
241
242         if (message == NULL) {
243                 GLOGD("Failed to invoke dbus method");
244                 return error;
245         }
246
247         g_variant_unref(message);
248
249         return ERROR_NONE;
250 }
251 error_e Wifi::GetPasspoint(int *enable)
252 {
253         GVariant *message = NULL;
254         error_e error = ERROR_NONE;
255
256         message = InvokeMethod(NETCONFIG_SERVICE,
257                 NETCONFIG_WIFI_PATH,
258                 NETCONFIG_WIFI_INTERFACE,
259                 GET_PASSPOINT,
260                 NULL,
261                 &error);
262
263         if (message == NULL) {
264                 GLOGD("Failed to invoke dbus method");
265                 return error;
266         }
267
268         g_variant_get(message, "(i)", enable);
269         g_variant_unref(message);
270
271         return ERROR_NONE;
272 }
273
274 error_e Wifi::SetPasspoint(int enable)
275 {
276         GVariant *message = NULL;
277         error_e error = ERROR_NONE;
278
279         message = InvokeMethod(NETCONFIG_SERVICE,
280                 NETCONFIG_WIFI_PATH,
281                 NETCONFIG_WIFI_INTERFACE,
282                 SET_PASSPOINT,
283                 g_variant_new("(i)", enable),
284                 &error);
285
286         if (message == NULL) {
287                 GLOGD("Failed to invoke dbus method");
288                 return error;
289         }
290
291         g_variant_unref(message);
292
293         return ERROR_NONE;
294 }
295
296 error_e Wifi::GetConfigIds(void)
297 {
298         GVariant *message = NULL;
299         error_e error = ERROR_NONE;
300
301         message = InvokeMethod(NETCONFIG_SERVICE,
302                 NETCONFIG_WIFI_PATH,
303                 NETCONFIG_WIFI_INTERFACE,
304                 GET_CONFIGIDS,
305                 NULL,
306                 &error);
307
308         if (message == NULL) {
309                 GLOGD("Failed to invoke dbus method");
310                 return error;
311         }
312
313         g_variant_unref(message);
314
315         return ERROR_NONE;
316 }
317
318 error_e Wifi::SaveConfiguration(const char *config_id, const char *name,
319                 const char *ssid, const char *passphrase)
320 {
321         GVariant *message = NULL;
322         error_e error = ERROR_NONE;
323
324         GVariantBuilder *b = NULL;
325         GVariant *params = NULL;
326
327         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
328         g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name));
329         g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid));
330         if (passphrase != NULL)
331                 g_variant_builder_add(b, "{sv}", "Passphrase", g_variant_new_string(passphrase));
332         params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b));
333         g_variant_builder_unref(b);
334
335         message = InvokeMethod(NETCONFIG_SERVICE,
336                 NETCONFIG_WIFI_PATH,
337                 NETCONFIG_WIFI_INTERFACE,
338                 SAVE_CONFIGURATION,
339                 params,
340                 &error);
341
342         if (message == NULL) {
343                 GLOGD("Failed to invoke dbus method");
344                 return error;
345         }
346
347         g_variant_unref(message);
348
349         return ERROR_NONE;
350 }
351
352 error_e Wifi::SaveEapConfiguration(const char *config_id, const char *name,
353                 const char *ssid)
354 {
355         GVariant *message = NULL;
356         error_e error = ERROR_NONE;
357
358         GVariantBuilder *b = NULL;
359         GVariant *params = NULL;
360
361         b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
362         g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name));
363         g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid));
364         params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b));
365         g_variant_builder_unref(b);
366
367         message = InvokeMethod(NETCONFIG_SERVICE,
368                 NETCONFIG_WIFI_PATH,
369                 NETCONFIG_WIFI_INTERFACE,
370                 SAVE_EAP_CONFIGURATION,
371                 params,
372                 &error);
373
374         if (message == NULL) {
375                 GLOGD("Failed to invoke dbus method");
376                 return error;
377         }
378
379         g_variant_unref(message);
380
381         return ERROR_NONE;
382 }
383
384 error_e Wifi::SetIpConflictPeriod(unsigned int time)
385 {
386         GVariant *message = NULL;
387         error_e error = ERROR_NONE;
388
389         message = InvokeMethod(NETCONFIG_SERVICE,
390                 NETCONFIG_WIFI_PATH,
391                 NETCONFIG_WIFI_INTERFACE,
392                 SET_IP_CONFLICT_PERIOD,
393                 g_variant_new("(u)", time),
394                 &error);
395
396         if (message == NULL) {
397                 GLOGD("Failed to invoke dbus method");
398                 return error;
399         }
400
401         g_variant_unref(message);
402
403         return ERROR_NONE;
404 }
405
406 error_e Wifi::RemoveConfiguration(const char *config_id)
407 {
408         GVariant *message = NULL;
409         error_e error = ERROR_NONE;
410
411         message = InvokeMethod(NETCONFIG_SERVICE,
412                 NETCONFIG_WIFI_PATH,
413                 NETCONFIG_WIFI_INTERFACE,
414                 REMOVE_CONFIGURATION,
415                 g_variant_new("(s)", config_id),
416                 &error);
417
418         if (message == NULL) {
419                 GLOGD("Failed to invoke dbus method");
420                 return error;
421         }
422
423         g_variant_unref(message);
424
425         return ERROR_NONE;
426 }
427
428 error_e Wifi::LoadConfiguration(const char *config_id)
429 {
430         GVariant *message = NULL;
431         error_e error = ERROR_NONE;
432
433         message = InvokeMethod(NETCONFIG_SERVICE,
434                 NETCONFIG_WIFI_PATH,
435                 NETCONFIG_WIFI_INTERFACE,
436                 LOAD_CONFIGURATION,
437                 g_variant_new("(s)", config_id),
438                 &error);
439
440         if (message == NULL) {
441                 GLOGD("Failed to invoke dbus method");
442                 return error;
443         }
444
445         g_variant_unref(message);
446
447         return ERROR_NONE;
448 }
449
450 error_e Wifi::LoadEapConfiguration(const char *config_id)
451 {
452         GVariant *message = NULL;
453         error_e error = ERROR_NONE;
454
455         message = InvokeMethod(NETCONFIG_SERVICE,
456                 NETCONFIG_WIFI_PATH,
457                 NETCONFIG_WIFI_INTERFACE,
458                 LOAD_EAP_CONFIGURATION,
459                 g_variant_new("(s)", config_id),
460                 &error);
461
462         if (message == NULL) {
463                 GLOGD("Failed to invoke dbus method");
464                 return error;
465         }
466
467         g_variant_unref(message);
468
469         return ERROR_NONE;
470 }
471
472 error_e Wifi::SetConfigField(const char *config_id, const char *key,
473                 const char *value)
474 {
475         GVariant *message = NULL;
476         error_e error = ERROR_NONE;
477
478         message = InvokeMethod(NETCONFIG_SERVICE,
479                 NETCONFIG_WIFI_PATH,
480                 NETCONFIG_WIFI_INTERFACE,
481                 SET_CONFIG_FIELD,
482                 g_variant_new("(sss)", config_id, key, value),
483                 &error);
484
485         if (message == NULL) {
486                 GLOGD("Failed to invoke dbus method");
487                 return error;
488         }
489
490         g_variant_unref(message);
491
492         return ERROR_NONE;
493 }
494
495 error_e Wifi::GetConfigPassphrase(const char *config_id, char *password)
496 {
497         GVariant *message = NULL;
498         error_e error = ERROR_NONE;
499
500         message = InvokeMethod(NETCONFIG_SERVICE,
501                 NETCONFIG_WIFI_PATH,
502                 NETCONFIG_WIFI_INTERFACE,
503                 GET_CONFIG_PASSPHRASE,
504                 g_variant_new("(s)", config_id),
505                 &error);
506
507         if (message == NULL) {
508                 GLOGD("Failed to invoke dbus method");
509                 return error;
510         }
511
512         g_variant_get(message, "(s)", password);
513         g_variant_unref(message);
514
515         return ERROR_NONE;
516 }
517
518 error_e Wifi::CreateEapConfig(const char *profile_name)
519 {
520         GVariant *message = NULL;
521         error_e error = ERROR_NONE;
522         GVariant *params = NULL;
523         GVariantBuilder *builder;
524
525         builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}"));
526         g_variant_builder_add(builder, "{ss}", "Type", "wifi");
527         g_variant_builder_add(builder, "{ss}",
528                         "Name", "gtest");
529
530         params = g_variant_new("(o@a{ss})", (gchar *)profile_name,
531                         g_variant_builder_end(builder));
532
533         g_variant_builder_unref(builder);
534
535         message = InvokeMethod(NETCONFIG_SERVICE,
536                 NETCONFIG_WIFI_PATH,
537                 NETCONFIG_WIFI_INTERFACE,
538                 CREATE_EAP_CONFIG,
539                 params,
540                 &error);
541
542         if (message == NULL) {
543                 GLOGD("Failed to invoke dbus method");
544                 return error;
545         }
546
547         g_variant_unref(message);
548
549         return ERROR_NONE;
550 }
551
552 error_e Wifi::DeleteEapConfig(const char *profile_name)
553 {
554         GVariant *message = NULL;
555         error_e error = ERROR_NONE;
556
557         message = InvokeMethod(NETCONFIG_SERVICE,
558                 NETCONFIG_WIFI_PATH,
559                 NETCONFIG_WIFI_INTERFACE,
560                 DELETE_EAP_CONFIG,
561                 g_variant_new("(s)", profile_name),
562                 &error);
563
564         if (message == NULL) {
565                 GLOGD("Failed to invoke dbus method");
566                 return error;
567         }
568
569         g_variant_unref(message);
570
571         return ERROR_NONE;
572 }
573
574 error_e Wifi::IpConflictSetEnable(bool detect)
575 {
576         GVariant *message = NULL;
577         error_e error = ERROR_NONE;
578
579         message = InvokeMethod(NETCONFIG_SERVICE,
580                 NETCONFIG_WIFI_PATH,
581                 NETCONFIG_WIFI_INTERFACE,
582                 IP_CONFLICT_SET_ENABLE,
583                 g_variant_new("(b)", detect),
584                 &error);
585
586         if (message == NULL) {
587                 GLOGD("Failed to invoke dbus method");
588                 return error;
589         }
590
591         g_variant_unref(message);
592
593         return ERROR_NONE;
594 }
595
596 error_e Wifi::GetSimImsi(char *imsi)
597 {
598         GVariant *message = NULL;
599         error_e error = ERROR_NONE;
600
601         message = InvokeMethod(NETCONFIG_SERVICE,
602                 NETCONFIG_WIFI_PATH,
603                 NETCONFIG_WIFI_INTERFACE,
604                 GET_SIM_IMSI,
605                 NULL,
606                 &error);
607
608         if (message == NULL) {
609                 GLOGD("Failed to invoke dbus method");
610                 return error;
611         }
612
613         g_variant_get(message, "(s)", imsi);
614         g_variant_unref(message);
615
616         return ERROR_NONE;
617 }
618
619 error_e Wifi::ReqSimAuth(const unsigned char *rand_data, unsigned int length,
620         gboolean *result)
621 {
622         GVariant *message = NULL;
623         error_e error = ERROR_NONE;
624         GVariantBuilder *b;
625         GVariant *v;
626         b = g_variant_builder_new(G_VARIANT_TYPE("ay"));
627         for(unsigned int i = 0;i < length;i++)
628                 g_variant_builder_add(b, "y", rand_data[i]);
629
630         v = g_variant_new("(ay)", b);
631         g_variant_builder_unref(b);
632
633         message = InvokeMethod(NETCONFIG_SERVICE,
634                 NETCONFIG_WIFI_PATH,
635                 NETCONFIG_WIFI_INTERFACE,
636                 REQ_SIM_AUTH,
637                 v,
638                 &error);
639
640         if (message == NULL) {
641                 GLOGD("Failed to invoke dbus method");
642                 return error;
643         }
644
645         g_variant_get(message, "(b)", result);
646         g_variant_unref(message);
647
648         return ERROR_NONE;
649 }
650
651 error_e Wifi::ReqAkaAuth(const unsigned char *rand_data, int rand_length,
652         const unsigned char *autn_data, int auth_length, gboolean *result)
653 {
654         GVariant *message = NULL;
655         error_e error = ERROR_NONE;
656         GVariantBuilder *b1, *b2;
657         GVariant *v;
658         b1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
659         for(int i = 0;i < rand_length;i++)
660                 g_variant_builder_add(b1, "y", rand_data[i]);
661
662         b2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
663         for(int i = 0;i < auth_length;i++)
664                 g_variant_builder_add(b2, "y", autn_data[i]);
665
666         v = g_variant_new("(@ay@ay)", g_variant_builder_end(b1), g_variant_builder_end(b2));
667
668         g_variant_builder_unref(b1);
669         g_variant_builder_unref(b2);
670
671         message = InvokeMethod(NETCONFIG_SERVICE,
672                 NETCONFIG_WIFI_PATH,
673                 NETCONFIG_WIFI_INTERFACE,
674                 REQ_AKA_AUTH,
675                 v,
676                 &error);
677
678         if (message == NULL) {
679                 GLOGD("Failed to invoke dbus method");
680                 return error;
681         }
682
683         g_variant_get(message, "(b)", result);
684         g_variant_unref(message);
685
686         return ERROR_NONE;
687 }
688
689 error_e Wifi::GetSimAuth(const unsigned char *auth_data, unsigned int length)
690 {
691         GVariant *message = NULL;
692         error_e error = ERROR_NONE;
693         GVariantBuilder *b;
694         GVariant *v;
695         b = g_variant_builder_new(G_VARIANT_TYPE("ay"));
696         for(unsigned int i = 0;i < length;i++)
697                 g_variant_builder_add(b, "y", auth_data[i]);
698
699         v = g_variant_new("(ay)", b);
700         g_variant_builder_unref(b);
701
702         message = InvokeMethod(NETCONFIG_SERVICE,
703                 NETCONFIG_WIFI_PATH,
704                 NETCONFIG_WIFI_INTERFACE,
705                 GET_SIM_AUTH,
706                 v,
707                 &error);
708
709         if (message == NULL) {
710                 GLOGD("Failed to invoke dbus method");
711                 return error;
712         }
713
714         g_variant_unref(message);
715
716         return ERROR_NONE;
717 }
718
719 error_e Wifi::CheckBlackList(const char *name, const char *sec_type,
720                 const char *eap, gboolean *allowed)
721 {
722         GVariant *message = NULL;
723         error_e error = ERROR_NONE;
724
725         message = InvokeMethod(NETCONFIG_SERVICE,
726                 NETCONFIG_WIFI_PATH,
727                 NETCONFIG_WIFI_INTERFACE,
728                 CHECK_BLACKLIST,
729                 g_variant_new("(sss)", name, sec_type, eap),
730                 &error);
731
732         if (message == NULL) {
733                 GLOGD("Failed to invoke dbus method");
734                 return error;
735         }
736
737         g_variant_get(message, "(b)", allowed);
738         g_variant_unref(message);
739
740         return ERROR_NONE;
741 }
742
743 error_e Wifi::TdlsDisconnect(const char *peer_mac_address, int *result)
744 {
745         GVariant *message = NULL;
746         error_e error = ERROR_NONE;
747
748         message = InvokeMethod(NETCONFIG_SERVICE,
749                 NETCONFIG_WIFI_PATH,
750                 NETCONFIG_WIFI_INTERFACE,
751                 TDLS_DISCONNECT,
752                 g_variant_new("(s)", peer_mac_address),
753                 &error);
754
755         if (message == NULL) {
756                 GLOGD("Failed to invoke dbus method");
757                 return error;
758         }
759
760         g_variant_get(message, "(i)", result);
761         g_variant_unref(message);
762
763         return ERROR_NONE;
764 }
765
766 error_e Wifi::TdlsConnectedPeer(char *peer_mac_address)
767 {
768         GVariant *message = NULL;
769         error_e error = ERROR_NONE;
770
771         message = InvokeMethod(NETCONFIG_SERVICE,
772                 NETCONFIG_WIFI_PATH,
773                 NETCONFIG_WIFI_INTERFACE,
774                 TDLS_CONNECTED_PEER,
775                 NULL,
776                 &error);
777
778         if (message == NULL) {
779                 GLOGD("Failed to invoke dbus method");
780                 return error;
781         }
782
783         g_variant_get(message, "(s)", peer_mac_address);
784         g_variant_unref(message);
785
786         return ERROR_NONE;
787 }
788
789 error_e Wifi::TdlsConnect(const char *peer_mac_address, int *result)
790 {
791         GVariant *message = NULL;
792         error_e error = ERROR_NONE;
793
794         message = InvokeMethod(NETCONFIG_SERVICE,
795                 NETCONFIG_WIFI_PATH,
796                 NETCONFIG_WIFI_INTERFACE,
797                 TDLS_CONNECT,
798                 g_variant_new("(s)", peer_mac_address),
799                 &error);
800
801         if (message == NULL) {
802                 GLOGD("Failed to invoke dbus method");
803                 return error;
804         }
805
806         g_variant_get(message, "(i)", result);
807         g_variant_unref(message);
808
809         return ERROR_NONE;
810 }
811
812 error_e Wifi::TdlsDiscover(const char *peer_mac_address, int *result)
813 {
814         GVariant *message = NULL;
815         error_e error = ERROR_NONE;
816
817         message = InvokeMethod(NETCONFIG_SERVICE,
818                 NETCONFIG_WIFI_PATH,
819                 NETCONFIG_WIFI_INTERFACE,
820                 TDLS_DISCOVER,
821                 g_variant_new("(s)", peer_mac_address),
822                 &error);
823
824         if (message == NULL) {
825                 GLOGD("Failed to invoke dbus method");
826                 return error;
827         }
828
829         g_variant_get(message, "(i)", result);
830         g_variant_unref(message);
831
832         return ERROR_NONE;
833 }
834
835 error_e Wifi::TdlsChannelSwitch(const char *peer_mac_address, int freq, int *result)
836 {
837         GVariant *message = NULL;
838         error_e error = ERROR_NONE;
839
840         message = InvokeMethod(NETCONFIG_SERVICE,
841                 NETCONFIG_WIFI_PATH,
842                 NETCONFIG_WIFI_INTERFACE,
843                 TDLS_CHANNEL_SWITCH,
844                 g_variant_new("(si)", peer_mac_address, freq),
845                 &error);
846
847         if (message == NULL) {
848                 GLOGD("Failed to invoke dbus method");
849                 return error;
850         }
851
852         g_variant_get(message, "(i)", result);
853         g_variant_unref(message);
854
855         return ERROR_NONE;
856 }
857
858 error_e Wifi::TdlsCancelChannelSwitch(const char *peer_mac_address, int *result)
859 {
860         GVariant *message = NULL;
861         error_e error = ERROR_NONE;
862
863         message = InvokeMethod(NETCONFIG_SERVICE,
864                 NETCONFIG_WIFI_PATH,
865                 NETCONFIG_WIFI_INTERFACE,
866                 TDLS_CANCEL_CHANNEL_SWITCH,
867                 g_variant_new("(s)", peer_mac_address),
868                 &error);
869
870         if (message == NULL) {
871                 GLOGD("Failed to invoke dbus method");
872                 return error;
873         }
874
875         g_variant_get(message, "(i)", result);
876         g_variant_unref(message);
877
878         return ERROR_NONE;
879 }
880
881 error_e Wifi::AddVsie(int frame_id, const char *vsie)
882 {
883         GVariant *message = NULL;
884         error_e error = ERROR_NONE;
885
886         message = InvokeMethod(NETCONFIG_SERVICE,
887                 NETCONFIG_WIFI_PATH,
888                 NETCONFIG_WIFI_INTERFACE,
889                 ADD_VSIE,
890                 g_variant_new("(is)", frame_id, vsie),
891                 &error);
892
893         if (message == NULL) {
894                 GLOGD("Failed to invoke dbus method");
895                 return error;
896         }
897
898         g_variant_unref(message);
899
900         return ERROR_NONE;
901 }
902
903 error_e Wifi::GetVsie(int frame_id, char *vsie)
904 {
905         GVariant *message = NULL;
906         error_e error = ERROR_NONE;
907
908         message = InvokeMethod(NETCONFIG_SERVICE,
909                 NETCONFIG_WIFI_PATH,
910                 NETCONFIG_WIFI_INTERFACE,
911                 GET_VSIE,
912                 g_variant_new("(i)", frame_id),
913                 &error);
914
915         if (message == NULL) {
916                 GLOGD("Failed to invoke dbus method");
917                 return error;
918         }
919
920         g_variant_get(message, "(s)", vsie);
921         g_variant_unref(message);
922
923         return ERROR_NONE;
924 }
925
926 error_e Wifi::RemoveVsie(int frame_id, const char *vsie)
927 {
928         GVariant *message = NULL;
929         error_e error = ERROR_NONE;
930
931         message = InvokeMethod(NETCONFIG_SERVICE,
932                 NETCONFIG_WIFI_PATH,
933                 NETCONFIG_WIFI_INTERFACE,
934                 REMOVE_VSIE,
935                 g_variant_new("(is)", frame_id, vsie),
936                 &error);
937
938         if (message == NULL) {
939                 GLOGD("Failed to invoke dbus method");
940                 return error;
941         }
942
943         g_variant_unref(message);
944
945         return ERROR_NONE;
946 }
947
948 error_e Wifi::EncryptPassphrase(char **enc_data, const char *passphrase)
949 {
950         GVariant *message = NULL;
951         error_e error = ERROR_NONE;
952
953         message = InvokeMethod(NETCONFIG_SERVICE,
954                 NETCONFIG_WIFI_PATH,
955                 NETCONFIG_WIFI_INTERFACE,
956                 ENCRYPT_PASSPHRASE,
957                 g_variant_new("(s)", passphrase),
958                 &error);
959
960         if (message == NULL) {
961                 GLOGD("Failed to invoke dbus method");
962                 return error;
963         }
964
965         g_variant_get(message, "(s)", enc_data);
966         g_variant_unref(message);
967
968         return ERROR_NONE;
969 }
970
971 error_e Wifi::DecryptPassphrase(const char *enc_data, char **passphrase)
972 {
973         GVariant *message = NULL;
974         error_e error = ERROR_NONE;
975
976         message = InvokeMethod(NETCONFIG_SERVICE,
977                 NETCONFIG_WIFI_PATH,
978                 NETCONFIG_WIFI_INTERFACE,
979                 DECRYPT_PASSPHRASE,
980                 g_variant_new("(s)", enc_data),
981                 &error);
982
983         if (message == NULL) {
984                 GLOGD("Failed to invoke dbus method");
985                 return error;
986         }
987
988         g_variant_get(message, "(s)", passphrase);
989         g_variant_unref(message);
990
991         return ERROR_NONE;
992 }
993
994
995 error_e Wifi::Stop(const char *device)
996 {
997         GVariant *message = NULL;
998         error_e error = ERROR_NONE;
999
1000         message = InvokeMethod(NETCONFIG_SERVICE,
1001                 NETCONFIG_WIFI_PATH,
1002                 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1003                 WIFI_FIRMWARE_STOP,
1004                 g_variant_new("(s)", device),
1005                 &error);
1006
1007         if (message == NULL) {
1008                 GLOGD("Failed to invoke dbus method");
1009                 return error;
1010         }
1011
1012         g_variant_unref(message);
1013
1014         return ERROR_NONE;
1015 }
1016
1017 error_e Wifi::Start(const char *device)
1018 {
1019         GVariant *message = NULL;
1020         error_e error = ERROR_NONE;
1021
1022         message = InvokeMethod(NETCONFIG_SERVICE,
1023                 NETCONFIG_WIFI_PATH,
1024                 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1025                 WIFI_FIRMWARE_START,
1026                 g_variant_new("(s)", device),
1027                 &error);
1028
1029         if (message == NULL) {
1030                 GLOGD("Failed to invoke dbus method");
1031                 return error;
1032         }
1033
1034         g_variant_unref(message);
1035
1036         return ERROR_NONE;
1037 }
1038
1039 error_e Wifi::LoadDriver(bool device_picker_test)
1040 {
1041         GVariant *message = NULL;
1042         error_e error = ERROR_NONE;
1043
1044         message = InvokeMethod(NETCONFIG_SERVICE,
1045                 NETCONFIG_WIFI_PATH,
1046                 NETCONFIG_WIFI_INTERFACE,
1047                 LOAD_DRIVER,
1048                 g_variant_new("(b)", device_picker_test),
1049                 &error);
1050
1051         if (message == NULL) {
1052                 GLOGD("Failed to invoke dbus method");
1053                 return error;
1054         }
1055
1056         g_variant_unref(message);
1057
1058         return ERROR_NONE;
1059 }
1060
1061 error_e Wifi::RemoveDriver()
1062 {
1063         GVariant *message = NULL;
1064         error_e error = ERROR_NONE;
1065
1066         message = InvokeMethod(NETCONFIG_SERVICE,
1067                 NETCONFIG_WIFI_PATH,
1068                 NETCONFIG_WIFI_INTERFACE,
1069                 REMOVE_DRIVER,
1070                 NULL,
1071                 &error);
1072
1073         if (message == NULL) {
1074                 GLOGD("Failed to invoke dbus method");
1075                 return error;
1076         }
1077
1078         g_variant_unref(message);
1079
1080         return ERROR_NONE;
1081 }