2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
37 error_e Wifi::GetWifiState(char *state)
39 GVariant *message = NULL;
40 error_e error = ERROR_NONE;
42 message = InvokeMethod(NETCONFIG_SERVICE,
44 NETCONFIG_WIFI_INTERFACE,
49 if (message == NULL) {
50 GLOGD("Failed to invoke dbus method");
54 g_variant_get(message, "(s)", state);
55 g_variant_unref(message);
60 error_e Wifi::IsIpConflictDetectEnabled(bool *state)
62 GVariant *message = NULL;
63 error_e error = ERROR_NONE;
65 message = InvokeMethod(NETCONFIG_SERVICE,
67 NETCONFIG_WIFI_INTERFACE,
68 IS_IP_CONFLICT_DETECT_ENABLED,
72 if (message == NULL) {
73 GLOGD("Failed to invoke dbus method");
77 g_variant_get(message, "(b)", state);
78 g_variant_unref(message);
83 error_e Wifi::SetBgscan(int scan_mode)
85 GVariant *message = NULL;
86 error_e error = ERROR_NONE;
88 message = InvokeMethod(NETCONFIG_SERVICE,
90 NETCONFIG_WIFI_INTERFACE,
92 g_variant_new("(u)", scan_mode),
95 if (message == NULL) {
96 GLOGD("Failed to invoke dbus method");
100 g_variant_unref(message);
105 error_e Wifi::GetAutoscan(bool *state)
107 GVariant *message = NULL;
108 error_e error = ERROR_NONE;
110 message = InvokeMethod(NETCONFIG_SERVICE,
112 NETCONFIG_WIFI_INTERFACE,
117 if (message == NULL) {
118 GLOGD("Failed to invoke dbus method");
122 g_variant_get(message, "(b)", state);
123 g_variant_unref(message);
128 error_e Wifi::GetIpConflictState(int *state)
130 GVariant *message = NULL;
131 error_e error = ERROR_NONE;
133 message = InvokeMethod(NETCONFIG_SERVICE,
135 NETCONFIG_WIFI_INTERFACE,
136 GET_IP_CONFLICT_STATE,
140 if (message == NULL) {
141 GLOGD("Failed to invoke dbus method");
145 g_variant_get(message, "(u)", state);
146 g_variant_unref(message);
151 error_e Wifi::GetIpConflictPeriod(int *period)
153 GVariant *message = NULL;
154 error_e error = ERROR_NONE;
156 message = InvokeMethod(NETCONFIG_SERVICE,
158 NETCONFIG_WIFI_INTERFACE,
159 GET_IP_CONFLICT_PERIOD,
163 if (message == NULL) {
164 GLOGD("Failed to invoke dbus method");
168 g_variant_get(message, "(u)", period);
169 g_variant_unref(message);
174 error_e Wifi::GetAutoscanmode(int *autoscanmode)
176 GVariant *message = NULL;
177 error_e error = ERROR_NONE;
179 message = InvokeMethod(NETCONFIG_SERVICE,
181 NETCONFIG_WIFI_INTERFACE,
186 if (message == NULL) {
187 GLOGD("Failed to invoke dbus method");
191 g_variant_get(message, "(u)", autoscanmode);
192 g_variant_unref(message);
197 error_e Wifi::NetlinkScan(const char *ssid)
199 GVariant *message = NULL;
200 error_e error = ERROR_NONE;
201 GVariantBuilder *builder;
202 GVariant *params = NULL;
205 return ERROR_INVALID_PARAMETER;
207 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
208 g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid));
210 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
211 g_variant_builder_unref(builder);
213 message = InvokeMethod(NETCONFIG_SERVICE,
215 NETCONFIG_WIFI_INTERFACE,
220 if (message == NULL) {
221 GLOGD("Failed to invoke dbus method");
225 g_variant_unref(message);
230 error_e Wifi::RequestWpsConnect(const char *param)
232 GVariant *message = NULL;
233 error_e error = ERROR_NONE;
235 message = InvokeMethod(NETCONFIG_SERVICE,
237 NETCONFIG_WIFI_INTERFACE,
239 g_variant_new("(s)", param),
242 if (message == NULL) {
243 GLOGD("Failed to invoke dbus method");
247 g_variant_unref(message);
251 error_e Wifi::GetPasspoint(int *enable)
253 GVariant *message = NULL;
254 error_e error = ERROR_NONE;
256 message = InvokeMethod(NETCONFIG_SERVICE,
258 NETCONFIG_WIFI_INTERFACE,
263 if (message == NULL) {
264 GLOGD("Failed to invoke dbus method");
268 g_variant_get(message, "(i)", enable);
269 g_variant_unref(message);
274 error_e Wifi::SetPasspoint(int enable)
276 GVariant *message = NULL;
277 error_e error = ERROR_NONE;
279 message = InvokeMethod(NETCONFIG_SERVICE,
281 NETCONFIG_WIFI_INTERFACE,
283 g_variant_new("(i)", enable),
286 if (message == NULL) {
287 GLOGD("Failed to invoke dbus method");
291 g_variant_unref(message);
296 error_e Wifi::GetConfigIds(void)
298 GVariant *message = NULL;
299 error_e error = ERROR_NONE;
301 message = InvokeMethod(NETCONFIG_SERVICE,
303 NETCONFIG_WIFI_INTERFACE,
308 if (message == NULL) {
309 GLOGD("Failed to invoke dbus method");
313 g_variant_unref(message);
318 error_e Wifi::SaveConfiguration(const char *config_id, const char *name,
319 const char *ssid, const char *passphrase)
321 GVariant *message = NULL;
322 error_e error = ERROR_NONE;
324 GVariantBuilder *b = NULL;
325 GVariant *params = NULL;
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);
335 message = InvokeMethod(NETCONFIG_SERVICE,
337 NETCONFIG_WIFI_INTERFACE,
342 if (message == NULL) {
343 GLOGD("Failed to invoke dbus method");
347 g_variant_unref(message);
352 error_e Wifi::SaveEapConfiguration(const char *config_id, const char *name,
355 GVariant *message = NULL;
356 error_e error = ERROR_NONE;
358 GVariantBuilder *b = NULL;
359 GVariant *params = NULL;
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);
367 message = InvokeMethod(NETCONFIG_SERVICE,
369 NETCONFIG_WIFI_INTERFACE,
370 SAVE_EAP_CONFIGURATION,
374 if (message == NULL) {
375 GLOGD("Failed to invoke dbus method");
379 g_variant_unref(message);
384 error_e Wifi::SetIpConflictPeriod(unsigned int time)
386 GVariant *message = NULL;
387 error_e error = ERROR_NONE;
389 message = InvokeMethod(NETCONFIG_SERVICE,
391 NETCONFIG_WIFI_INTERFACE,
392 SET_IP_CONFLICT_PERIOD,
393 g_variant_new("(u)", time),
396 if (message == NULL) {
397 GLOGD("Failed to invoke dbus method");
401 g_variant_unref(message);
406 error_e Wifi::RemoveConfiguration(const char *config_id)
408 GVariant *message = NULL;
409 error_e error = ERROR_NONE;
411 message = InvokeMethod(NETCONFIG_SERVICE,
413 NETCONFIG_WIFI_INTERFACE,
414 REMOVE_CONFIGURATION,
415 g_variant_new("(s)", config_id),
418 if (message == NULL) {
419 GLOGD("Failed to invoke dbus method");
423 g_variant_unref(message);
428 error_e Wifi::LoadConfiguration(const char *config_id)
430 GVariant *message = NULL;
431 error_e error = ERROR_NONE;
433 message = InvokeMethod(NETCONFIG_SERVICE,
435 NETCONFIG_WIFI_INTERFACE,
437 g_variant_new("(s)", config_id),
440 if (message == NULL) {
441 GLOGD("Failed to invoke dbus method");
445 g_variant_unref(message);
450 error_e Wifi::LoadEapConfiguration(const char *config_id)
452 GVariant *message = NULL;
453 error_e error = ERROR_NONE;
455 message = InvokeMethod(NETCONFIG_SERVICE,
457 NETCONFIG_WIFI_INTERFACE,
458 LOAD_EAP_CONFIGURATION,
459 g_variant_new("(s)", config_id),
462 if (message == NULL) {
463 GLOGD("Failed to invoke dbus method");
467 g_variant_unref(message);
472 error_e Wifi::SetConfigField(const char *config_id, const char *key,
475 GVariant *message = NULL;
476 error_e error = ERROR_NONE;
478 message = InvokeMethod(NETCONFIG_SERVICE,
480 NETCONFIG_WIFI_INTERFACE,
482 g_variant_new("(sss)", config_id, key, value),
485 if (message == NULL) {
486 GLOGD("Failed to invoke dbus method");
490 g_variant_unref(message);
495 error_e Wifi::GetConfigPassphrase(const char *config_id, char *password)
497 GVariant *message = NULL;
498 error_e error = ERROR_NONE;
500 message = InvokeMethod(NETCONFIG_SERVICE,
502 NETCONFIG_WIFI_INTERFACE,
503 GET_CONFIG_PASSPHRASE,
504 g_variant_new("(s)", config_id),
507 if (message == NULL) {
508 GLOGD("Failed to invoke dbus method");
512 g_variant_get(message, "(s)", password);
513 g_variant_unref(message);
518 error_e Wifi::CreateEapConfig(const char *profile_name)
520 GVariant *message = NULL;
521 error_e error = ERROR_NONE;
522 GVariant *params = NULL;
523 GVariantBuilder *builder;
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}",
530 params = g_variant_new("(o@a{ss})", (gchar *)profile_name,
531 g_variant_builder_end(builder));
533 g_variant_builder_unref(builder);
535 message = InvokeMethod(NETCONFIG_SERVICE,
537 NETCONFIG_WIFI_INTERFACE,
542 if (message == NULL) {
543 GLOGD("Failed to invoke dbus method");
547 g_variant_unref(message);
552 error_e Wifi::DeleteEapConfig(const char *profile_name)
554 GVariant *message = NULL;
555 error_e error = ERROR_NONE;
557 message = InvokeMethod(NETCONFIG_SERVICE,
559 NETCONFIG_WIFI_INTERFACE,
561 g_variant_new("(s)", profile_name),
564 if (message == NULL) {
565 GLOGD("Failed to invoke dbus method");
569 g_variant_unref(message);
574 error_e Wifi::IpConflictSetEnable(bool detect)
576 GVariant *message = NULL;
577 error_e error = ERROR_NONE;
579 message = InvokeMethod(NETCONFIG_SERVICE,
581 NETCONFIG_WIFI_INTERFACE,
582 IP_CONFLICT_SET_ENABLE,
583 g_variant_new("(b)", detect),
586 if (message == NULL) {
587 GLOGD("Failed to invoke dbus method");
591 g_variant_unref(message);
596 error_e Wifi::GetSimImsi(char *imsi)
598 GVariant *message = NULL;
599 error_e error = ERROR_NONE;
601 message = InvokeMethod(NETCONFIG_SERVICE,
603 NETCONFIG_WIFI_INTERFACE,
608 if (message == NULL) {
609 GLOGD("Failed to invoke dbus method");
613 g_variant_get(message, "(s)", imsi);
614 g_variant_unref(message);
619 error_e Wifi::ReqSimAuth(const unsigned char *rand_data, unsigned int length,
622 GVariant *message = NULL;
623 error_e error = ERROR_NONE;
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]);
630 v = g_variant_new("(ay)", b);
631 g_variant_builder_unref(b);
633 message = InvokeMethod(NETCONFIG_SERVICE,
635 NETCONFIG_WIFI_INTERFACE,
640 if (message == NULL) {
641 GLOGD("Failed to invoke dbus method");
645 g_variant_get(message, "(b)", result);
646 g_variant_unref(message);
651 error_e Wifi::ReqAkaAuth(const unsigned char *rand_data, int rand_length,
652 const unsigned char *autn_data, int auth_length, bool *result)
654 GVariant *message = NULL;
655 error_e error = ERROR_NONE;
656 GVariantBuilder *b1, *b2;
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]);
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]);
666 v = g_variant_new("(@ay@ay)", g_variant_builder_end(b1), g_variant_builder_end(b2));
668 g_variant_builder_unref(b1);
669 g_variant_builder_unref(b2);
671 message = InvokeMethod(NETCONFIG_SERVICE,
673 NETCONFIG_WIFI_INTERFACE,
678 if (message == NULL) {
679 GLOGD("Failed to invoke dbus method");
683 g_variant_get(message, "(b)", result);
684 g_variant_unref(message);
689 error_e Wifi::GetSimAuth(const unsigned char *auth_data, unsigned int length)
691 GVariant *message = NULL;
692 error_e error = ERROR_NONE;
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]);
699 v = g_variant_new("(ay)", b);
700 g_variant_builder_unref(b);
702 message = InvokeMethod(NETCONFIG_SERVICE,
704 NETCONFIG_WIFI_INTERFACE,
709 if (message == NULL) {
710 GLOGD("Failed to invoke dbus method");
714 g_variant_unref(message);
719 error_e Wifi::CheckBlackList(const char *name, const char *sec_type,
720 const char *eap, bool *allowed)
722 GVariant *message = NULL;
723 error_e error = ERROR_NONE;
725 message = InvokeMethod(NETCONFIG_SERVICE,
727 NETCONFIG_WIFI_INTERFACE,
729 g_variant_new("(sss)", name, sec_type, eap),
732 if (message == NULL) {
733 GLOGD("Failed to invoke dbus method");
737 g_variant_get(message, "(b)", allowed);
738 g_variant_unref(message);
743 error_e Wifi::TdlsDisconnect(const char *peer_mac_address, int *result)
745 GVariant *message = NULL;
746 error_e error = ERROR_NONE;
748 message = InvokeMethod(NETCONFIG_SERVICE,
750 NETCONFIG_WIFI_INTERFACE,
752 g_variant_new("(s)", peer_mac_address),
755 if (message == NULL) {
756 GLOGD("Failed to invoke dbus method");
760 g_variant_get(message, "(i)", result);
761 g_variant_unref(message);
766 error_e Wifi::TdlsConnectedPeer(char *peer_mac_address)
768 GVariant *message = NULL;
769 error_e error = ERROR_NONE;
771 message = InvokeMethod(NETCONFIG_SERVICE,
773 NETCONFIG_WIFI_INTERFACE,
778 if (message == NULL) {
779 GLOGD("Failed to invoke dbus method");
783 g_variant_get(message, "(s)", peer_mac_address);
784 g_variant_unref(message);
789 error_e Wifi::TdlsConnect(const char *peer_mac_address, int *result)
791 GVariant *message = NULL;
792 error_e error = ERROR_NONE;
794 message = InvokeMethod(NETCONFIG_SERVICE,
796 NETCONFIG_WIFI_INTERFACE,
798 g_variant_new("(s)", peer_mac_address),
801 if (message == NULL) {
802 GLOGD("Failed to invoke dbus method");
806 g_variant_get(message, "(i)", result);
807 g_variant_unref(message);
812 error_e Wifi::TdlsDiscover(const char *peer_mac_address, int *result)
814 GVariant *message = NULL;
815 error_e error = ERROR_NONE;
817 message = InvokeMethod(NETCONFIG_SERVICE,
819 NETCONFIG_WIFI_INTERFACE,
821 g_variant_new("(s)", peer_mac_address),
824 if (message == NULL) {
825 GLOGD("Failed to invoke dbus method");
829 g_variant_get(message, "(i)", result);
830 g_variant_unref(message);
835 error_e Wifi::TdlsChannelSwitch(const char *peer_mac_address, int freq, int *result)
837 GVariant *message = NULL;
838 error_e error = ERROR_NONE;
840 message = InvokeMethod(NETCONFIG_SERVICE,
842 NETCONFIG_WIFI_INTERFACE,
844 g_variant_new("(si)", peer_mac_address, freq),
847 if (message == NULL) {
848 GLOGD("Failed to invoke dbus method");
852 g_variant_get(message, "(i)", result);
853 g_variant_unref(message);
858 error_e Wifi::TdlsCancelChannelSwitch(const char *peer_mac_address, int *result)
860 GVariant *message = NULL;
861 error_e error = ERROR_NONE;
863 message = InvokeMethod(NETCONFIG_SERVICE,
865 NETCONFIG_WIFI_INTERFACE,
866 TDLS_CANCEL_CHANNEL_SWITCH,
867 g_variant_new("(s)", peer_mac_address),
870 if (message == NULL) {
871 GLOGD("Failed to invoke dbus method");
875 g_variant_get(message, "(i)", result);
876 g_variant_unref(message);
881 error_e Wifi::AddVsie(int frame_id, const char *vsie)
883 GVariant *message = NULL;
884 error_e error = ERROR_NONE;
886 message = InvokeMethod(NETCONFIG_SERVICE,
888 NETCONFIG_WIFI_INTERFACE,
890 g_variant_new("(is)", frame_id, vsie),
893 if (message == NULL) {
894 GLOGD("Failed to invoke dbus method");
898 g_variant_unref(message);
903 error_e Wifi::GetVsie(int frame_id, char *vsie)
905 GVariant *message = NULL;
906 error_e error = ERROR_NONE;
908 message = InvokeMethod(NETCONFIG_SERVICE,
910 NETCONFIG_WIFI_INTERFACE,
912 g_variant_new("(i)", frame_id),
915 if (message == NULL) {
916 GLOGD("Failed to invoke dbus method");
920 g_variant_get(message, "(s)", vsie);
921 g_variant_unref(message);
926 error_e Wifi::RemoveVsie(int frame_id, const char *vsie)
928 GVariant *message = NULL;
929 error_e error = ERROR_NONE;
931 message = InvokeMethod(NETCONFIG_SERVICE,
933 NETCONFIG_WIFI_INTERFACE,
935 g_variant_new("(is)", frame_id, vsie),
938 if (message == NULL) {
939 GLOGD("Failed to invoke dbus method");
943 g_variant_unref(message);
948 error_e Wifi::EncryptPassphrase(char **enc_data, const char *passphrase)
950 GVariant *message = NULL;
951 error_e error = ERROR_NONE;
953 message = InvokeMethod(NETCONFIG_SERVICE,
955 NETCONFIG_WIFI_INTERFACE,
957 g_variant_new("(s)", passphrase),
960 if (message == NULL) {
961 GLOGD("Failed to invoke dbus method");
965 g_variant_get(message, "(s)", enc_data);
966 g_variant_unref(message);
971 error_e Wifi::DecryptPassphrase(const char *enc_data, char **passphrase)
973 GVariant *message = NULL;
974 error_e error = ERROR_NONE;
976 message = InvokeMethod(NETCONFIG_SERVICE,
978 NETCONFIG_WIFI_INTERFACE,
980 g_variant_new("(s)", enc_data),
983 if (message == NULL) {
984 GLOGD("Failed to invoke dbus method");
988 g_variant_get(message, "(s)", passphrase);
989 g_variant_unref(message);
995 error_e Wifi::Stop(const char *device)
997 GVariant *message = NULL;
998 error_e error = ERROR_NONE;
1000 message = InvokeMethod(NETCONFIG_SERVICE,
1001 NETCONFIG_WIFI_PATH,
1002 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1004 g_variant_new("(s)", device),
1007 if (message == NULL) {
1008 GLOGD("Failed to invoke dbus method");
1012 g_variant_unref(message);
1017 error_e Wifi::Start(const char *device)
1019 GVariant *message = NULL;
1020 error_e error = ERROR_NONE;
1022 message = InvokeMethod(NETCONFIG_SERVICE,
1023 NETCONFIG_WIFI_PATH,
1024 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1025 WIFI_FIRMWARE_START,
1026 g_variant_new("(s)", device),
1029 if (message == NULL) {
1030 GLOGD("Failed to invoke dbus method");
1034 g_variant_unref(message);
1039 error_e Wifi::LoadDriver(bool device_picker_test)
1041 GVariant *message = NULL;
1042 error_e error = ERROR_NONE;
1044 message = InvokeMethod(NETCONFIG_SERVICE,
1045 NETCONFIG_WIFI_PATH,
1046 NETCONFIG_WIFI_INTERFACE,
1048 g_variant_new("(b)", device_picker_test),
1051 if (message == NULL) {
1052 GLOGD("Failed to invoke dbus method");
1056 g_variant_unref(message);
1061 error_e Wifi::RemoveDriver()
1063 GVariant *message = NULL;
1064 error_e error = ERROR_NONE;
1066 message = InvokeMethod(NETCONFIG_SERVICE,
1067 NETCONFIG_WIFI_PATH,
1068 NETCONFIG_WIFI_INTERFACE,
1073 if (message == NULL) {
1074 GLOGD("Failed to invoke dbus method");
1078 g_variant_unref(message);