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;
204 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
205 if (ssid[0] != '\0') {
206 g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid));
208 return ERROR_INVALID_PARAMETER;
211 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
212 g_variant_builder_unref(builder);
214 message = InvokeMethod(NETCONFIG_SERVICE,
216 NETCONFIG_WIFI_INTERFACE,
221 if (message == NULL) {
222 GLOGD("Failed to invoke dbus method");
226 g_variant_unref(message);
231 error_e Wifi::RequestWpsConnect(const char *param)
233 GVariant *message = NULL;
234 error_e error = ERROR_NONE;
236 message = InvokeMethod(NETCONFIG_SERVICE,
238 NETCONFIG_WIFI_INTERFACE,
240 g_variant_new("(s)", param),
243 if (message == NULL) {
244 GLOGD("Failed to invoke dbus method");
248 g_variant_unref(message);
252 error_e Wifi::GetPasspoint(int *enable)
254 GVariant *message = NULL;
255 error_e error = ERROR_NONE;
257 message = InvokeMethod(NETCONFIG_SERVICE,
259 NETCONFIG_WIFI_INTERFACE,
264 if (message == NULL) {
265 GLOGD("Failed to invoke dbus method");
269 g_variant_get(message, "(i)", enable);
270 g_variant_unref(message);
275 error_e Wifi::SetPasspoint(int enable)
277 GVariant *message = NULL;
278 error_e error = ERROR_NONE;
280 message = InvokeMethod(NETCONFIG_SERVICE,
282 NETCONFIG_WIFI_INTERFACE,
284 g_variant_new("(i)", enable),
287 if (message == NULL) {
288 GLOGD("Failed to invoke dbus method");
292 g_variant_unref(message);
297 error_e Wifi::GetConfigIds(void)
299 GVariant *message = NULL;
300 error_e error = ERROR_NONE;
302 message = InvokeMethod(NETCONFIG_SERVICE,
304 NETCONFIG_WIFI_INTERFACE,
309 if (message == NULL) {
310 GLOGD("Failed to invoke dbus method");
314 g_variant_unref(message);
319 error_e Wifi::SaveConfiguration(const char *config_id, const char *name,
320 const char *ssid, const char *passphrase)
322 GVariant *message = NULL;
323 error_e error = ERROR_NONE;
325 GVariantBuilder *b = NULL;
326 GVariant *params = NULL;
328 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
329 g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name));
330 g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid));
331 if (passphrase != NULL)
332 g_variant_builder_add(b, "{sv}", "Passphrase", g_variant_new_string(passphrase));
333 params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b));
334 g_variant_builder_unref(b);
336 message = InvokeMethod(NETCONFIG_SERVICE,
338 NETCONFIG_WIFI_INTERFACE,
343 if (message == NULL) {
344 GLOGD("Failed to invoke dbus method");
348 g_variant_unref(message);
353 error_e Wifi::SaveEapConfiguration(const char *config_id, const char *name,
356 GVariant *message = NULL;
357 error_e error = ERROR_NONE;
359 GVariantBuilder *b = NULL;
360 GVariant *params = NULL;
362 b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
363 g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name));
364 g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid));
365 params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b));
366 g_variant_builder_unref(b);
368 message = InvokeMethod(NETCONFIG_SERVICE,
370 NETCONFIG_WIFI_INTERFACE,
371 SAVE_EAP_CONFIGURATION,
375 if (message == NULL) {
376 GLOGD("Failed to invoke dbus method");
380 g_variant_unref(message);
385 error_e Wifi::SetIpConflictPeriod(unsigned int time)
387 GVariant *message = NULL;
388 error_e error = ERROR_NONE;
390 message = InvokeMethod(NETCONFIG_SERVICE,
392 NETCONFIG_WIFI_INTERFACE,
393 SET_IP_CONFLICT_PERIOD,
394 g_variant_new("(u)", time),
397 if (message == NULL) {
398 GLOGD("Failed to invoke dbus method");
402 g_variant_unref(message);
407 error_e Wifi::RemoveConfiguration(const char *config_id)
409 GVariant *message = NULL;
410 error_e error = ERROR_NONE;
412 message = InvokeMethod(NETCONFIG_SERVICE,
414 NETCONFIG_WIFI_INTERFACE,
415 REMOVE_CONFIGURATION,
416 g_variant_new("(s)", config_id),
419 if (message == NULL) {
420 GLOGD("Failed to invoke dbus method");
424 g_variant_unref(message);
429 error_e Wifi::LoadConfiguration(const char *config_id)
431 GVariant *message = NULL;
432 error_e error = ERROR_NONE;
434 message = InvokeMethod(NETCONFIG_SERVICE,
436 NETCONFIG_WIFI_INTERFACE,
438 g_variant_new("(s)", config_id),
441 if (message == NULL) {
442 GLOGD("Failed to invoke dbus method");
446 g_variant_unref(message);
451 error_e Wifi::LoadEapConfiguration(const char *config_id)
453 GVariant *message = NULL;
454 error_e error = ERROR_NONE;
456 message = InvokeMethod(NETCONFIG_SERVICE,
458 NETCONFIG_WIFI_INTERFACE,
459 LOAD_EAP_CONFIGURATION,
460 g_variant_new("(s)", config_id),
463 if (message == NULL) {
464 GLOGD("Failed to invoke dbus method");
468 g_variant_unref(message);
473 error_e Wifi::SetConfigField(const char *config_id, const char *key,
476 GVariant *message = NULL;
477 error_e error = ERROR_NONE;
479 message = InvokeMethod(NETCONFIG_SERVICE,
481 NETCONFIG_WIFI_INTERFACE,
483 g_variant_new("(sss)", config_id, key, value),
486 if (message == NULL) {
487 GLOGD("Failed to invoke dbus method");
491 g_variant_unref(message);
496 error_e Wifi::GetConfigPassphrase(const char *config_id, char *password)
498 GVariant *message = NULL;
499 error_e error = ERROR_NONE;
501 message = InvokeMethod(NETCONFIG_SERVICE,
503 NETCONFIG_WIFI_INTERFACE,
504 GET_CONFIG_PASSPHRASE,
505 g_variant_new("(s)", config_id),
508 if (message == NULL) {
509 GLOGD("Failed to invoke dbus method");
513 g_variant_get(message, "(s)", password);
514 g_variant_unref(message);
519 error_e Wifi::CreateEapConfig(const char *profile_name)
521 GVariant *message = NULL;
522 error_e error = ERROR_NONE;
523 GVariant *params = NULL;
524 GVariantBuilder *builder;
526 builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}"));
527 g_variant_builder_add(builder, "{ss}", "Type", "wifi");
528 g_variant_builder_add(builder, "{ss}",
531 params = g_variant_new("(o@a{ss})", (gchar *)profile_name,
532 g_variant_builder_end(builder));
534 g_variant_builder_unref(builder);
536 message = InvokeMethod(NETCONFIG_SERVICE,
538 NETCONFIG_WIFI_INTERFACE,
543 if (message == NULL) {
544 GLOGD("Failed to invoke dbus method");
548 g_variant_unref(message);
553 error_e Wifi::DeleteEapConfig(const char *profile_name)
555 GVariant *message = NULL;
556 error_e error = ERROR_NONE;
558 message = InvokeMethod(NETCONFIG_SERVICE,
560 NETCONFIG_WIFI_INTERFACE,
562 g_variant_new("(s)", profile_name),
565 if (message == NULL) {
566 GLOGD("Failed to invoke dbus method");
570 g_variant_unref(message);
575 error_e Wifi::IpConflictSetEnable(bool detect)
577 GVariant *message = NULL;
578 error_e error = ERROR_NONE;
580 message = InvokeMethod(NETCONFIG_SERVICE,
582 NETCONFIG_WIFI_INTERFACE,
583 IP_CONFLICT_SET_ENABLE,
584 g_variant_new("(b)", detect),
587 if (message == NULL) {
588 GLOGD("Failed to invoke dbus method");
592 g_variant_unref(message);
597 error_e Wifi::GetSimImsi(char *imsi)
599 GVariant *message = NULL;
600 error_e error = ERROR_NONE;
602 message = InvokeMethod(NETCONFIG_SERVICE,
604 NETCONFIG_WIFI_INTERFACE,
609 if (message == NULL) {
610 GLOGD("Failed to invoke dbus method");
614 g_variant_get(message, "(s)", imsi);
615 g_variant_unref(message);
620 error_e Wifi::ReqSimAuth(const unsigned char *rand_data, unsigned int length,
623 GVariant *message = NULL;
624 error_e error = ERROR_NONE;
627 b = g_variant_builder_new(G_VARIANT_TYPE("ay"));
628 for(unsigned int i = 0;i < length;i++)
629 g_variant_builder_add(b, "y", rand_data[i]);
631 v = g_variant_new("(ay)", b);
632 g_variant_builder_unref(b);
634 message = InvokeMethod(NETCONFIG_SERVICE,
636 NETCONFIG_WIFI_INTERFACE,
641 if (message == NULL) {
642 GLOGD("Failed to invoke dbus method");
646 g_variant_get(message, "(b)", result);
647 g_variant_unref(message);
652 error_e Wifi::ReqAkaAuth(const unsigned char *rand_data, int rand_length,
653 const unsigned char *autn_data, int auth_length, bool *result)
655 GVariant *message = NULL;
656 error_e error = ERROR_NONE;
657 GVariantBuilder *b1, *b2;
659 b1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
660 for(int i = 0;i < rand_length;i++)
661 g_variant_builder_add(b1, "y", rand_data[i]);
663 b2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
664 for(int i = 0;i < auth_length;i++)
665 g_variant_builder_add(b2, "y", autn_data[i]);
667 v = g_variant_new("(@ay@ay)", g_variant_builder_end(b1), g_variant_builder_end(b2));
669 g_variant_builder_unref(b1);
670 g_variant_builder_unref(b2);
672 message = InvokeMethod(NETCONFIG_SERVICE,
674 NETCONFIG_WIFI_INTERFACE,
679 if (message == NULL) {
680 GLOGD("Failed to invoke dbus method");
684 g_variant_get(message, "(b)", result);
685 g_variant_unref(message);
690 error_e Wifi::GetSimAuth(const unsigned char *auth_data, unsigned int length)
692 GVariant *message = NULL;
693 error_e error = ERROR_NONE;
696 b = g_variant_builder_new(G_VARIANT_TYPE("ay"));
697 for(unsigned int i = 0;i < length;i++)
698 g_variant_builder_add(b, "y", auth_data[i]);
700 v = g_variant_new("(ay)", b);
701 g_variant_builder_unref(b);
703 message = InvokeMethod(NETCONFIG_SERVICE,
705 NETCONFIG_WIFI_INTERFACE,
710 if (message == NULL) {
711 GLOGD("Failed to invoke dbus method");
715 g_variant_unref(message);
720 error_e Wifi::CheckBlackList(const char *name, const char *sec_type,
721 const char *eap, bool *allowed)
723 GVariant *message = NULL;
724 error_e error = ERROR_NONE;
726 message = InvokeMethod(NETCONFIG_SERVICE,
728 NETCONFIG_WIFI_INTERFACE,
730 g_variant_new("(sss)", name, sec_type, eap),
733 if (message == NULL) {
734 GLOGD("Failed to invoke dbus method");
738 g_variant_get(message, "(b)", allowed);
739 g_variant_unref(message);
744 error_e Wifi::TdlsDisconnect(const char *peer_mac_address, int *result)
746 GVariant *message = NULL;
747 error_e error = ERROR_NONE;
749 message = InvokeMethod(NETCONFIG_SERVICE,
751 NETCONFIG_WIFI_INTERFACE,
753 g_variant_new("(s)", peer_mac_address),
756 if (message == NULL) {
757 GLOGD("Failed to invoke dbus method");
761 g_variant_get(message, "(i)", result);
762 g_variant_unref(message);
767 error_e Wifi::TdlsConnectedPeer(char *peer_mac_address)
769 GVariant *message = NULL;
770 error_e error = ERROR_NONE;
772 message = InvokeMethod(NETCONFIG_SERVICE,
774 NETCONFIG_WIFI_INTERFACE,
779 if (message == NULL) {
780 GLOGD("Failed to invoke dbus method");
784 g_variant_get(message, "(s)", peer_mac_address);
785 g_variant_unref(message);
790 error_e Wifi::TdlsConnect(const char *peer_mac_address, int *result)
792 GVariant *message = NULL;
793 error_e error = ERROR_NONE;
795 message = InvokeMethod(NETCONFIG_SERVICE,
797 NETCONFIG_WIFI_INTERFACE,
799 g_variant_new("(s)", peer_mac_address),
802 if (message == NULL) {
803 GLOGD("Failed to invoke dbus method");
807 g_variant_get(message, "(i)", result);
808 g_variant_unref(message);
813 error_e Wifi::TdlsDiscover(const char *peer_mac_address, int *result)
815 GVariant *message = NULL;
816 error_e error = ERROR_NONE;
818 message = InvokeMethod(NETCONFIG_SERVICE,
820 NETCONFIG_WIFI_INTERFACE,
822 g_variant_new("(s)", peer_mac_address),
825 if (message == NULL) {
826 GLOGD("Failed to invoke dbus method");
830 g_variant_get(message, "(i)", result);
831 g_variant_unref(message);
836 error_e Wifi::TdlsChannelSwitch(const char *peer_mac_address, int freq, int *result)
838 GVariant *message = NULL;
839 error_e error = ERROR_NONE;
841 message = InvokeMethod(NETCONFIG_SERVICE,
843 NETCONFIG_WIFI_INTERFACE,
845 g_variant_new("(si)", peer_mac_address, freq),
848 if (message == NULL) {
849 GLOGD("Failed to invoke dbus method");
853 g_variant_get(message, "(i)", result);
854 g_variant_unref(message);
859 error_e Wifi::TdlsCancelChannelSwitch(const char *peer_mac_address, int *result)
861 GVariant *message = NULL;
862 error_e error = ERROR_NONE;
864 message = InvokeMethod(NETCONFIG_SERVICE,
866 NETCONFIG_WIFI_INTERFACE,
867 TDLS_CANCEL_CHANNEL_SWITCH,
868 g_variant_new("(s)", peer_mac_address),
871 if (message == NULL) {
872 GLOGD("Failed to invoke dbus method");
876 g_variant_get(message, "(i)", result);
877 g_variant_unref(message);
882 error_e Wifi::AddVsie(int frame_id, const char *vsie)
884 GVariant *message = NULL;
885 error_e error = ERROR_NONE;
887 message = InvokeMethod(NETCONFIG_SERVICE,
889 NETCONFIG_WIFI_INTERFACE,
891 g_variant_new("(is)", frame_id, vsie),
894 if (message == NULL) {
895 GLOGD("Failed to invoke dbus method");
899 g_variant_unref(message);
904 error_e Wifi::GetVsie(int frame_id, char *vsie)
906 GVariant *message = NULL;
907 error_e error = ERROR_NONE;
909 message = InvokeMethod(NETCONFIG_SERVICE,
911 NETCONFIG_WIFI_INTERFACE,
913 g_variant_new("(i)", frame_id),
916 if (message == NULL) {
917 GLOGD("Failed to invoke dbus method");
921 g_variant_get(message, "(s)", vsie);
922 g_variant_unref(message);
927 error_e Wifi::RemoveVsie(int frame_id, const char *vsie)
929 GVariant *message = NULL;
930 error_e error = ERROR_NONE;
932 message = InvokeMethod(NETCONFIG_SERVICE,
934 NETCONFIG_WIFI_INTERFACE,
936 g_variant_new("(is)", frame_id, vsie),
939 if (message == NULL) {
940 GLOGD("Failed to invoke dbus method");
944 g_variant_unref(message);
949 error_e Wifi::EncryptPassphrase(char **enc_data, const char *passphrase)
951 GVariant *message = NULL;
952 error_e error = ERROR_NONE;
954 message = InvokeMethod(NETCONFIG_SERVICE,
956 NETCONFIG_WIFI_INTERFACE,
958 g_variant_new("(s)", passphrase),
961 if (message == NULL) {
962 GLOGD("Failed to invoke dbus method");
966 g_variant_get(message, "(s)", enc_data);
967 g_variant_unref(message);
972 error_e Wifi::DecryptPassphrase(const char *enc_data, char **passphrase)
974 GVariant *message = NULL;
975 error_e error = ERROR_NONE;
977 message = InvokeMethod(NETCONFIG_SERVICE,
979 NETCONFIG_WIFI_INTERFACE,
981 g_variant_new("(s)", enc_data),
984 if (message == NULL) {
985 GLOGD("Failed to invoke dbus method");
989 g_variant_get(message, "(s)", passphrase);
990 g_variant_unref(message);
996 error_e Wifi::Stop(const char *device)
998 GVariant *message = NULL;
999 error_e error = ERROR_NONE;
1001 message = InvokeMethod(NETCONFIG_SERVICE,
1002 NETCONFIG_WIFI_PATH,
1003 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1005 g_variant_new("(s)", device),
1008 if (message == NULL) {
1009 GLOGD("Failed to invoke dbus method");
1013 g_variant_unref(message);
1018 error_e Wifi::Start(const char *device)
1020 GVariant *message = NULL;
1021 error_e error = ERROR_NONE;
1023 message = InvokeMethod(NETCONFIG_SERVICE,
1024 NETCONFIG_WIFI_PATH,
1025 NETCONFIG_WIFI_FIRMWARE_INTERFACE,
1026 WIFI_FIRMWARE_START,
1027 g_variant_new("(s)", device),
1030 if (message == NULL) {
1031 GLOGD("Failed to invoke dbus method");
1035 g_variant_unref(message);
1040 error_e Wifi::LoadDriver(bool device_picker_test)
1042 GVariant *message = NULL;
1043 error_e error = ERROR_NONE;
1045 message = InvokeMethod(NETCONFIG_SERVICE,
1046 NETCONFIG_WIFI_PATH,
1047 NETCONFIG_WIFI_INTERFACE,
1049 g_variant_new("(b)", device_picker_test),
1052 if (message == NULL) {
1053 GLOGD("Failed to invoke dbus method");
1057 g_variant_unref(message);
1062 error_e Wifi::RemoveDriver()
1064 GVariant *message = NULL;
1065 error_e error = ERROR_NONE;
1067 message = InvokeMethod(NETCONFIG_SERVICE,
1068 NETCONFIG_WIFI_PATH,
1069 NETCONFIG_WIFI_INTERFACE,
1074 if (message == NULL) {
1075 GLOGD("Failed to invoke dbus method");
1079 g_variant_unref(message);