2 * Copyright (c) 2012-2013 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.
21 #include "net_wifi_private.h"
23 static GSList *ap_handle_list = NULL;
26 wifi_device_state_changed_cb device_state_cb;
27 void *device_state_user_data;
28 wifi_scan_finished_cb bg_scan_cb;
29 void *bg_scan_user_data;
30 wifi_scan_finished_cb scan_request_cb;
31 void *scan_request_user_data;
32 wifi_connection_state_changed_cb connection_state_cb;
33 void *connection_state_user_data;
34 wifi_activated_cb activated_cb;
35 void *activated_user_data;
36 wifi_deactivated_cb deactivated_cb;
37 void *deactivated_user_data;
38 wifi_connected_cb connected_cb;
39 void *connected_user_data;
40 wifi_disconnected_cb disconnected_cb;
41 void *disconnected_user_data;
44 struct _profile_list_s {
46 net_profile_info_t *profiles;
49 static struct _wifi_cb_s wifi_callbacks = {0,};
50 static struct _profile_list_s profile_iterator = {0, NULL};
53 static wifi_error_e __libnet_convert_to_ap_error_type(net_err_t err_type)
57 return WIFI_ERROR_NONE;
58 case NET_ERR_APP_ALREADY_REGISTERED:
59 return WIFI_ERROR_INVALID_OPERATION;
60 case NET_ERR_APP_NOT_REGISTERED:
61 return WIFI_ERROR_INVALID_OPERATION;
62 case NET_ERR_NO_ACTIVE_CONNECTIONS:
63 return WIFI_ERROR_NO_CONNECTION;
64 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
65 return WIFI_ERROR_ALREADY_EXISTS;
66 case NET_ERR_CONNECTION_DHCP_FAILED:
67 return WIFI_ERROR_DHCP_FAILED;
68 case NET_ERR_CONNECTION_INVALID_KEY:
69 return WIFI_ERROR_INVALID_KEY;
70 case NET_ERR_IN_PROGRESS:
71 return WIFI_ERROR_NOW_IN_PROGRESS;
72 case NET_ERR_OPERATION_ABORTED:
73 return WIFI_ERROR_OPERATION_ABORTED;
74 case NET_ERR_TIME_OUT:
75 return WIFI_ERROR_NO_REPLY;
77 return WIFI_ERROR_OPERATION_FAILED;
81 static const char *__libnet_convert_ap_error_type_to_string(wifi_error_e err_type)
86 case WIFI_ERROR_INVALID_PARAMETER:
87 return "INVALID_PARAMETER";
88 case WIFI_ERROR_OUT_OF_MEMORY:
89 return "OUT_OF_MEMORY";
90 case WIFI_ERROR_INVALID_OPERATION:
91 return "INVALID_OPERATION";
92 case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
93 return "ADDRESS_FAMILY_NOT_SUPPORTED";
94 case WIFI_ERROR_OPERATION_FAILED:
95 return "OPERATION_FAILED";
96 case WIFI_ERROR_NO_CONNECTION:
97 return "NO_CONNECTION";
98 case WIFI_ERROR_NOW_IN_PROGRESS:
99 return "NOW_IN_PROGRESS";
100 case WIFI_ERROR_ALREADY_EXISTS:
101 return "ALREADY_EXISTS";
102 case WIFI_ERROR_OPERATION_ABORTED:
103 return "OPERATION_ABORTED";
104 case WIFI_ERROR_DHCP_FAILED:
105 return "DHCP_FAILED";
106 case WIFI_ERROR_INVALID_KEY:
107 return "INVALID_KEY";
108 case WIFI_ERROR_NO_REPLY:
110 case WIFI_ERROR_SECURITY_RESTRICTED:
111 return "SECURITY_RESTRICTED";
117 static const char *__libnet_convert_ap_state_to_string(wifi_connection_state_e state)
120 case WIFI_CONNECTION_STATE_DISCONNECTED:
121 return "DISCONNECTED";
122 case WIFI_CONNECTION_STATE_ASSOCIATION:
123 return "ASSOCIATION";
124 case WIFI_CONNECTION_STATE_CONFIGURATION:
125 return "CONFIGURATION";
126 case WIFI_CONNECTION_STATE_CONNECTED:
133 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
135 if (profile_list->count > 0)
136 g_free(profile_list->profiles);
138 profile_list->count = 0;
139 profile_list->profiles = NULL;
142 static void __libnet_update_profile_iterator(void)
144 struct _profile_list_s wifi_profiles = {0, NULL};
146 __libnet_clear_profile_list(&profile_iterator);
148 net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
149 WIFI_LOG(WIFI_INFO, "Wifi profile count : %d\n", wifi_profiles.count);
151 if (wifi_profiles.count == 0)
154 profile_iterator.count = wifi_profiles.count;
155 profile_iterator.profiles = wifi_profiles.profiles;
158 static void __libnet_convert_profile_info_to_wifi_info(net_wifi_connection_info_t *wifi_info,
159 net_profile_info_t *ap_info)
161 g_strlcpy(wifi_info->essid, ap_info->ProfileInfo.Wlan.essid, NET_WLAN_ESSID_LEN+1);
162 wifi_info->wlan_mode = ap_info->ProfileInfo.Wlan.wlan_mode;
163 memcpy(&wifi_info->security_info, &ap_info->ProfileInfo.Wlan.security_info, sizeof(wlan_security_info_t));
166 static int __libnet_connect_with_wifi_info(net_profile_info_t *ap_info)
168 net_wifi_connection_info_t wifi_info;
169 memset(&wifi_info, 0, sizeof(net_wifi_connection_info_t));
171 __libnet_convert_profile_info_to_wifi_info(&wifi_info, ap_info);
173 if (net_open_connection_with_wifi_info(&wifi_info) != NET_ERR_NONE)
174 return WIFI_ERROR_OPERATION_FAILED;
176 return WIFI_ERROR_NONE;
179 static void __libnet_state_changed_cb(char *profile_name, net_profile_info_t *profile_info,
180 wifi_connection_state_e state)
182 if (profile_name == NULL)
185 if (profile_info == NULL) {
186 WIFI_LOG(WIFI_ERROR, "Error!! Profile info not found! : %s\n", profile_name);
190 ap_handle_list = g_slist_append(ap_handle_list, (wifi_ap_h)profile_info);
192 if (wifi_callbacks.connection_state_cb)
193 wifi_callbacks.connection_state_cb(state, (wifi_ap_h)profile_info,
194 wifi_callbacks.connection_state_user_data);
196 ap_handle_list = g_slist_remove(ap_handle_list, (wifi_ap_h)profile_info);
199 static void __libnet_set_activated_cb(wifi_activated_cb user_cb, void *user_data)
202 wifi_callbacks.activated_cb = user_cb;
203 wifi_callbacks.activated_user_data = user_data;
207 static void __libnet_activated_cb(wifi_error_e result)
209 if (wifi_callbacks.activated_cb)
210 wifi_callbacks.activated_cb(result, wifi_callbacks.activated_user_data);
212 wifi_callbacks.activated_cb = NULL;
213 wifi_callbacks.activated_user_data = NULL;
216 static void __libnet_set_deactivated_cb(wifi_disconnected_cb user_cb, void *user_data)
219 wifi_callbacks.deactivated_cb = user_cb;
220 wifi_callbacks.deactivated_user_data = user_data;
224 static void __libnet_deactivated_cb(wifi_error_e result)
226 if (wifi_callbacks.deactivated_cb)
227 wifi_callbacks.deactivated_cb(result, wifi_callbacks.deactivated_user_data);
229 wifi_callbacks.deactivated_cb = NULL;
230 wifi_callbacks.deactivated_user_data = NULL;
233 static void __libnet_power_on_off_cb(net_event_info_t *event_cb, bool is_requested)
235 if (wifi_callbacks.device_state_cb == NULL &&
236 wifi_callbacks.activated_cb == NULL &&
237 wifi_callbacks.deactivated_cb == NULL)
240 wifi_error_e error_code = WIFI_ERROR_NONE;
241 wifi_device_state_e state;
242 net_wifi_state_t *wifi_state = (net_wifi_state_t*)event_cb->Data;
244 if (event_cb->Error == NET_ERR_NONE &&
245 event_cb->Datalength == sizeof(net_wifi_state_t)) {
247 if (*wifi_state == WIFI_ON) {
248 WIFI_LOG(WIFI_INFO, "Wi-Fi State : Power ON\n");
249 state = WIFI_DEVICE_STATE_ACTIVATED;
250 } else if (*wifi_state == WIFI_OFF) {
251 WIFI_LOG(WIFI_INFO, "Wi-Fi State : Power OFF\n");
252 state = WIFI_DEVICE_STATE_DEACTIVATED;
253 __libnet_clear_profile_list(&profile_iterator);
255 WIFI_LOG(WIFI_INFO, "Wi-Fi State : Unknown\n");
256 error_code = WIFI_ERROR_OPERATION_FAILED;
257 state = WIFI_DEVICE_STATE_DEACTIVATED;
260 WIFI_LOG(WIFI_ERROR, "Wi-Fi Power on/off request failed! Error [%d]\n", event_cb->Error);
261 error_code = WIFI_ERROR_OPERATION_FAILED;
262 state = WIFI_DEVICE_STATE_DEACTIVATED;
265 __libnet_activated_cb(error_code);
266 __libnet_deactivated_cb(error_code);
268 if (wifi_callbacks.device_state_cb)
269 wifi_callbacks.device_state_cb(state, wifi_callbacks.device_state_user_data);
272 static void __libnet_scan_cb(net_event_info_t *event_cb, bool is_requested)
274 wifi_error_e error_code = WIFI_ERROR_NONE;
276 if (event_cb->Error != NET_ERR_NONE) {
277 WIFI_LOG(WIFI_ERROR, "Scan failed!, Error [%d]\n", event_cb->Error);
278 error_code = WIFI_ERROR_OPERATION_FAILED;
281 if (wifi_callbacks.scan_request_cb) {
282 wifi_callbacks.scan_request_cb(error_code, wifi_callbacks.scan_request_user_data);
283 wifi_callbacks.scan_request_cb = NULL;
284 wifi_callbacks.scan_request_user_data = NULL;
288 if (wifi_callbacks.bg_scan_cb != NULL)
289 wifi_callbacks.bg_scan_cb(error_code, wifi_callbacks.bg_scan_user_data);
292 static void __libnet_set_connected_cb(wifi_connected_cb user_cb, void *user_data)
295 wifi_callbacks.connected_cb = user_cb;
296 wifi_callbacks.connected_user_data = user_data;
300 static void __libnet_connected_cb(wifi_error_e result)
302 if (wifi_callbacks.connected_cb)
303 wifi_callbacks.connected_cb(result, wifi_callbacks.connected_user_data);
305 wifi_callbacks.connected_cb = NULL;
306 wifi_callbacks.connected_user_data = NULL;
309 static void __libnet_set_disconnected_cb(wifi_disconnected_cb user_cb, void *user_data)
312 wifi_callbacks.disconnected_cb = user_cb;
313 wifi_callbacks.disconnected_user_data = user_data;
317 static void __libnet_disconnected_cb(wifi_error_e result)
319 if (wifi_callbacks.disconnected_cb)
320 wifi_callbacks.disconnected_cb(result, wifi_callbacks.disconnected_user_data);
322 wifi_callbacks.disconnected_cb = NULL;
323 wifi_callbacks.disconnected_user_data = NULL;
326 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
328 bool is_requested = false;
329 net_profile_info_t *prof_info_p = NULL;
330 net_profile_info_t prof_info;
331 wifi_error_e result = WIFI_ERROR_NONE;
333 switch (event_cb->Event) {
334 case NET_EVENT_OPEN_RSP:
335 case NET_EVENT_WIFI_WPS_RSP:
338 case NET_EVENT_OPEN_IND:
339 if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return;
341 result = __libnet_convert_to_ap_error_type(event_cb->Error);
342 WIFI_LOG(WIFI_INFO, "Got Open RSP/IND : %s\n",
343 __libnet_convert_ap_error_type_to_string(result));
346 __libnet_connected_cb(result);
348 switch (event_cb->Error) {
350 WIFI_LOG(WIFI_INFO, "Connection open succeeded\n");
352 if (event_cb->Datalength == sizeof(net_profile_info_t))
353 prof_info_p = (net_profile_info_t*)event_cb->Data;
355 __libnet_state_changed_cb(event_cb->ProfileName, prof_info_p,
356 WIFI_CONNECTION_STATE_CONNECTED);
359 WIFI_LOG(WIFI_ERROR, "Connection open failed!\n");
363 if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
364 __libnet_state_changed_cb(event_cb->ProfileName, &prof_info,
365 WIFI_CONNECTION_STATE_DISCONNECTED);
367 __libnet_state_changed_cb(event_cb->ProfileName, NULL,
368 WIFI_CONNECTION_STATE_DISCONNECTED);
371 case NET_EVENT_CLOSE_RSP:
374 case NET_EVENT_CLOSE_IND:
375 if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return;
377 result = __libnet_convert_to_ap_error_type(event_cb->Error);
378 WIFI_LOG(WIFI_INFO, "Got Close RSP/IND : %s\n",
379 __libnet_convert_ap_error_type_to_string(result));
382 __libnet_disconnected_cb(result);
384 switch (event_cb->Error) {
386 /* Successful PDP Deactivation */
387 WIFI_LOG(WIFI_INFO, "Connection close succeeded!\n");
388 if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
389 __libnet_state_changed_cb(event_cb->ProfileName, &prof_info,
390 WIFI_CONNECTION_STATE_DISCONNECTED);
392 __libnet_state_changed_cb(event_cb->ProfileName, NULL,
393 WIFI_CONNECTION_STATE_DISCONNECTED);
396 WIFI_LOG(WIFI_ERROR, "Connection close failed!\n");
401 case NET_EVENT_NET_STATE_IND:
402 if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return;
404 WIFI_LOG(WIFI_INFO, "Got State changed IND\n");
406 if (event_cb->Datalength != sizeof(net_state_type_t))
409 net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data;
410 wifi_connection_state_e ap_state = _wifi_convert_to_ap_state(*profile_state);
413 "Profile State : %s, profile name : %s\n",
414 __libnet_convert_ap_state_to_string(ap_state),
415 event_cb->ProfileName);
417 if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
418 __libnet_state_changed_cb(event_cb->ProfileName, &prof_info, ap_state);
420 __libnet_state_changed_cb(event_cb->ProfileName, NULL, ap_state);
424 case NET_EVENT_WIFI_SCAN_RSP:
425 case NET_EVENT_WIFI_SCAN_IND:
426 WIFI_LOG(WIFI_ERROR, "Got wifi scan IND\n");
427 __libnet_scan_cb(event_cb, is_requested);
429 case NET_EVENT_WIFI_POWER_RSP:
432 case NET_EVENT_WIFI_POWER_IND:
433 WIFI_LOG(WIFI_ERROR, "Got wifi power IND\n");
434 __libnet_power_on_off_cb(event_cb, is_requested);
437 WIFI_LOG(WIFI_ERROR, "Error! Unknown Event\n\n");
441 bool _wifi_libnet_init(void)
445 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_WIFI, NULL);
446 if (rv != NET_ERR_NONE)
452 bool _wifi_libnet_deinit(void)
454 if (net_deregister_client_ext(NET_DEVICE_WIFI) != NET_ERR_NONE)
457 __libnet_clear_profile_list(&profile_iterator);
458 g_slist_free_full(ap_handle_list, g_free);
459 ap_handle_list = NULL;
460 memset(&wifi_callbacks, 0, sizeof(struct _wifi_cb_s));
465 int _wifi_activate(wifi_activated_cb callback, void* user_data)
469 rv = net_wifi_power_on();
470 if (rv == NET_ERR_NONE) {
471 __libnet_set_activated_cb(callback, user_data);
472 return WIFI_ERROR_NONE;
473 } else if (rv == NET_ERR_INVALID_OPERATION)
474 return WIFI_ERROR_INVALID_OPERATION;
476 return WIFI_ERROR_OPERATION_FAILED;
479 int _wifi_deactivate(wifi_deactivated_cb callback, void* user_data)
483 rv = net_wifi_power_off();
484 if (rv == NET_ERR_NONE) {
485 __libnet_set_deactivated_cb(callback, user_data);
486 return WIFI_ERROR_NONE;
487 } else if (rv == NET_ERR_INVALID_OPERATION)
488 return WIFI_ERROR_INVALID_OPERATION;
490 return WIFI_ERROR_OPERATION_FAILED;
493 bool _wifi_libnet_check_ap_validity(wifi_ap_h ap_h)
498 for (list = ap_handle_list; list; list = list->next)
499 if (ap_h == list->data) return true;
501 for (;i < profile_iterator.count;i++)
502 if (ap_h == &profile_iterator.profiles[i]) return true;
507 void _wifi_libnet_add_to_ap_list(wifi_ap_h ap_h)
509 ap_handle_list = g_slist_append(ap_handle_list, ap_h);
512 void _wifi_libnet_remove_from_ap_list(wifi_ap_h ap_h)
514 ap_handle_list = g_slist_remove(ap_handle_list, ap_h);
518 bool _wifi_libnet_check_profile_name_validity(const char *profile_name)
520 const char *profile_header = "/net/connman/service/wifi_";
524 if (profile_name == NULL || strlen(profile_name) <= strlen(profile_header)) {
525 WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n");
529 string_len = strlen(profile_name);
531 if (strncmp(profile_header, profile_name, strlen(profile_header)) == 0) {
532 for (;i < string_len;i++) {
533 if (isgraph(profile_name[i]) == 0) {
534 WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n");
539 WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n");
546 bool _wifi_libnet_get_wifi_device_state(wifi_device_state_e *device_state)
548 net_wifi_state_t wlan_state;
549 net_profile_name_t profile_name;
551 if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) {
552 WIFI_LOG(WIFI_ERROR, "Error!! net_get_wifi_state() failed.\n");
556 switch (wlan_state) {
558 *device_state = WIFI_DEVICE_STATE_DEACTIVATED;
561 case WIFI_CONNECTING:
563 case WIFI_DISCONNECTING:
564 *device_state = WIFI_DEVICE_STATE_ACTIVATED;
567 WIFI_LOG(WIFI_ERROR, "Error!! Unknown state\n");
574 bool _wifi_libnet_get_wifi_state(wifi_connection_state_e* connection_state)
576 net_wifi_state_t wlan_state = 0;
577 net_profile_name_t profile_name;
579 if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) {
580 WIFI_LOG(WIFI_ERROR, "Error!! net_get_wifi_state() failed.\n");
584 switch (wlan_state) {
587 *connection_state = WIFI_CONNECTION_STATE_DISCONNECTED;
589 case WIFI_CONNECTING:
590 *connection_state = WIFI_CONNECTION_STATE_ASSOCIATION;
593 *connection_state = WIFI_CONNECTION_STATE_CONNECTED;
595 case WIFI_DISCONNECTING:
596 *connection_state = WIFI_CONNECTION_STATE_CONNECTED;
599 WIFI_LOG(WIFI_ERROR, "Error!! Unknown state\n");
606 int _wifi_libnet_get_intf_name(char** name)
608 if (profile_iterator.count == 0)
609 __libnet_update_profile_iterator();
611 if (profile_iterator.count == 0) {
612 WIFI_LOG(WIFI_ERROR, "Error!! There is no AP\n");
613 return WIFI_ERROR_OPERATION_FAILED;
616 *name = g_strdup(profile_iterator.profiles->ProfileInfo.Wlan.net_info.DevName);
618 return WIFI_ERROR_OUT_OF_MEMORY;
620 return WIFI_ERROR_NONE;
623 int _wifi_libnet_scan_request(wifi_scan_finished_cb callback, void* user_data)
626 rv = net_scan_wifi();
628 if (rv == NET_ERR_NONE) {
629 wifi_callbacks.scan_request_cb = callback;
630 wifi_callbacks.scan_request_user_data = user_data;
631 return WIFI_ERROR_NONE;
632 } else if (rv == NET_ERR_INVALID_OPERATION)
633 return WIFI_ERROR_INVALID_OPERATION;
635 return WIFI_ERROR_OPERATION_FAILED;
638 int _wifi_libnet_get_connected_profile(wifi_ap_h *ap)
641 wifi_ap_h ap_h = NULL;
643 __libnet_update_profile_iterator();
645 for (;i < profile_iterator.count;i++) {
646 if (profile_iterator.profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
647 profile_iterator.profiles[i].ProfileState == NET_STATE_TYPE_READY) {
648 ap_h = (wifi_ap_h)(&profile_iterator.profiles[i]);
654 WIFI_LOG(WIFI_ERROR, "Error!! There is no connected AP.\n");
655 return WIFI_ERROR_NO_CONNECTION;
658 *ap = g_try_malloc0(sizeof(net_profile_info_t));
660 return WIFI_ERROR_OUT_OF_MEMORY;
662 memcpy(*ap, ap_h, sizeof(net_profile_info_t));
664 _wifi_libnet_add_to_ap_list(*ap);
666 return WIFI_ERROR_NONE;
669 bool _wifi_libnet_foreach_found_aps(wifi_found_ap_cb callback, void *user_data)
674 __libnet_update_profile_iterator();
676 if (profile_iterator.count == 0) {
677 WIFI_LOG(WIFI_INFO, "There is no APs.\n");
681 for (;i < profile_iterator.count;i++) {
682 rv = callback((wifi_ap_h)(&profile_iterator.profiles[i]), user_data);
683 if (rv == false) break;
689 int _wifi_libnet_open_profile(wifi_ap_h ap_h, wifi_connected_cb callback, void* user_data)
691 net_profile_info_t *ap_info = ap_h;
692 net_profile_name_t profile_name;
695 g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
697 if (ap_info->ProfileInfo.Wlan.security_info.sec_mode == WLAN_SEC_MODE_IEEE8021X)
698 rv = __libnet_connect_with_wifi_info(ap_info);
699 else if (_wifi_libnet_check_profile_name_validity(ap_info->ProfileName) == false)
700 rv = __libnet_connect_with_wifi_info(ap_info);
702 rv = net_open_connection_with_profile(profile_name.ProfileName);
704 if (rv != NET_ERR_NONE)
705 return WIFI_ERROR_OPERATION_FAILED;
707 __libnet_set_connected_cb(callback, user_data);
709 return WIFI_ERROR_NONE;
712 int _wifi_libnet_close_profile(wifi_ap_h ap_h, wifi_disconnected_cb callback, void* user_data)
714 net_profile_info_t *ap_info = ap_h;
715 net_profile_name_t profile_name;
717 g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
719 if (net_close_connection(profile_name.ProfileName) != NET_ERR_NONE)
720 return WIFI_ERROR_OPERATION_FAILED;
722 __libnet_set_disconnected_cb(callback, user_data);
724 return WIFI_ERROR_NONE;
727 int _wifi_libnet_connect_with_wps(wifi_ap_h ap_h, wifi_connected_cb callback, void* user_data)
729 net_profile_info_t *ap_info = ap_h;
730 net_wifi_wps_info_t wps_info;
731 net_profile_name_t profile_name;
733 memset(&wps_info, 0 , sizeof(net_wifi_wps_info_t));
734 g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
736 wps_info.type = WIFI_WPS_PBC;
738 if (net_wifi_enroll_wps(profile_name.ProfileName, &wps_info) != NET_ERR_NONE)
739 return WIFI_ERROR_OPERATION_FAILED;
741 __libnet_set_connected_cb(callback, user_data);
743 return WIFI_ERROR_NONE;
746 int _wifi_libnet_forget_ap(wifi_ap_h ap)
749 net_profile_name_t profile_name;
750 net_profile_info_t *ap_info = ap;
752 g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
754 rv = net_delete_profile(profile_name.ProfileName);
755 if (rv != NET_ERR_NONE)
756 return WIFI_ERROR_OPERATION_FAILED;
758 return WIFI_ERROR_NONE;
761 int _wifi_set_power_on_off_cb(wifi_device_state_changed_cb callback, void *user_data)
763 if (wifi_callbacks.device_state_cb)
764 return WIFI_ERROR_INVALID_OPERATION;
766 wifi_callbacks.device_state_cb = callback;
767 wifi_callbacks.device_state_user_data = user_data;
769 return WIFI_ERROR_NONE;
772 int _wifi_unset_power_on_off_cb(void)
774 if (wifi_callbacks.device_state_cb == NULL)
775 return WIFI_ERROR_INVALID_OPERATION;
777 wifi_callbacks.device_state_cb = NULL;
778 wifi_callbacks.device_state_user_data = NULL;
780 return WIFI_ERROR_NONE;
783 int _wifi_set_background_scan_cb(wifi_scan_finished_cb callback, void *user_data)
785 if (wifi_callbacks.bg_scan_cb)
786 return WIFI_ERROR_INVALID_OPERATION;
788 wifi_callbacks.bg_scan_cb = callback;
789 wifi_callbacks.bg_scan_user_data = user_data;
791 return WIFI_ERROR_NONE;
794 int _wifi_unset_background_scan_cb(void)
796 if (wifi_callbacks.bg_scan_cb == NULL)
797 return WIFI_ERROR_INVALID_OPERATION;
799 wifi_callbacks.bg_scan_cb = NULL;
800 wifi_callbacks.bg_scan_user_data = NULL;
802 return WIFI_ERROR_NONE;
805 int _wifi_set_connection_state_cb(wifi_connection_state_changed_cb callback, void *user_data)
807 if (wifi_callbacks.connection_state_cb)
808 return WIFI_ERROR_INVALID_OPERATION;
810 wifi_callbacks.connection_state_cb = callback;
811 wifi_callbacks.connection_state_user_data = user_data;
813 return WIFI_ERROR_NONE;
816 int _wifi_unset_connection_state_cb()
818 if (wifi_callbacks.connection_state_cb == NULL)
819 return WIFI_ERROR_INVALID_OPERATION;
821 wifi_callbacks.connection_state_cb = NULL;
822 wifi_callbacks.connection_state_user_data = NULL;
824 return WIFI_ERROR_NONE;
827 int _wifi_update_ap_info(net_profile_info_t *ap_info)
829 if (net_modify_profile(ap_info->ProfileName, ap_info) != NET_ERR_NONE)
830 return WIFI_ERROR_OPERATION_FAILED;
832 return WIFI_ERROR_NONE;