5 * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <gweb/gweb.h>
33 struct connman_wispr_message {
35 const char *current_element;
39 char *abort_login_url;
41 char *access_procedure;
42 char *access_location;
46 enum connman_wispr_result {
47 CONNMAN_WISPR_RESULT_UNKNOWN = 0,
48 CONNMAN_WISPR_RESULT_LOGIN = 1,
49 CONNMAN_WISPR_RESULT_ONLINE = 2,
50 CONNMAN_WISPR_RESULT_FAILED = 3,
58 struct connman_wispr_portal_context {
59 struct connman_service *service;
60 enum connman_ipconfig_type type;
61 struct connman_wispr_portal *wispr_portal;
63 /* Portal/WISPr common */
68 const char *status_url;
73 GWebParser *wispr_parser;
74 struct connman_wispr_message wispr_msg;
80 enum connman_wispr_result wispr_result;
87 struct connman_wispr_portal {
88 struct connman_wispr_portal_context *ipv4_context;
89 struct connman_wispr_portal_context *ipv6_context;
92 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
94 static GHashTable *wispr_portal_list = NULL;
96 static char *online_check_ipv4_url = NULL;
97 static char *online_check_ipv6_url = NULL;
98 static bool enable_online_to_ready_transition = false;
100 static void connman_wispr_message_init(struct connman_wispr_message *msg)
104 msg->has_error = false;
105 msg->current_element = NULL;
107 msg->message_type = -1;
108 msg->response_code = -1;
110 g_free(msg->login_url);
111 msg->login_url = NULL;
113 g_free(msg->abort_login_url);
114 msg->abort_login_url = NULL;
116 g_free(msg->logoff_url);
117 msg->logoff_url = NULL;
119 g_free(msg->access_procedure);
120 msg->access_procedure = NULL;
122 g_free(msg->access_location);
123 msg->access_location = NULL;
125 g_free(msg->location_name);
126 msg->location_name = NULL;
129 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
131 while (wp_context->route_list) {
132 struct wispr_route *route = wp_context->route_list->data;
134 DBG("free route to %s if %d type %d", route->address,
135 route->if_index, wp_context->type);
137 switch (wp_context->type) {
138 case CONNMAN_IPCONFIG_TYPE_IPV4:
139 connman_inet_del_host_route(route->if_index,
142 case CONNMAN_IPCONFIG_TYPE_IPV6:
143 connman_inet_del_ipv6_host_route(route->if_index,
146 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
147 case CONNMAN_IPCONFIG_TYPE_ALL:
151 g_free(route->address);
154 wp_context->route_list =
155 g_slist_delete_link(wp_context->route_list,
156 wp_context->route_list);
160 static void free_connman_wispr_portal_context(
161 struct connman_wispr_portal_context *wp_context)
163 DBG("context %p", wp_context);
168 if (wp_context->wispr_portal) {
169 if (wp_context->wispr_portal->ipv4_context == wp_context)
170 wp_context->wispr_portal->ipv4_context = NULL;
172 if (wp_context->wispr_portal->ipv6_context == wp_context)
173 wp_context->wispr_portal->ipv6_context = NULL;
176 if (wp_context->token > 0)
177 connman_proxy_lookup_cancel(wp_context->token);
179 if (wp_context->request_id > 0)
180 g_web_cancel_request(wp_context->web, wp_context->request_id);
182 if (wp_context->timeout > 0)
183 g_source_remove(wp_context->timeout);
186 g_web_unref(wp_context->web);
188 g_free(wp_context->redirect_url);
190 if (wp_context->wispr_parser)
191 g_web_parser_unref(wp_context->wispr_parser);
193 connman_wispr_message_init(&wp_context->wispr_msg);
195 g_free(wp_context->wispr_username);
196 g_free(wp_context->wispr_password);
197 g_free(wp_context->wispr_formdata);
199 free_wispr_routes(wp_context);
204 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
206 return g_try_new0(struct connman_wispr_portal_context, 1);
209 static void free_connman_wispr_portal(gpointer data)
211 struct connman_wispr_portal *wispr_portal = data;
218 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
219 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
221 g_free(wispr_portal);
224 static const char *message_type_to_string(int message_type)
226 switch (message_type) {
228 return "Initial redirect message";
230 return "Proxy notification";
232 return "Authentication notification";
234 return "Logoff notification";
236 return "Response to Authentication Poll";
238 return "Response to Abort Login";
244 static const char *response_code_to_string(int response_code)
246 switch (response_code) {
250 return "Login succeeded";
252 return "Login failed";
254 return "RADIUS server error/timeout";
256 return "RADIUS server not enabled";
258 return "Logoff succeeded";
260 return "Login aborted";
262 return "Proxy detection/repeat operation";
264 return "Authentication pending";
266 return "Access gateway internal error";
275 WISPR_ELEMENT_NONE = 0,
276 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
277 WISPR_ELEMENT_ACCESS_LOCATION = 2,
278 WISPR_ELEMENT_LOCATION_NAME = 3,
279 WISPR_ELEMENT_LOGIN_URL = 4,
280 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
281 WISPR_ELEMENT_MESSAGE_TYPE = 6,
282 WISPR_ELEMENT_RESPONSE_CODE = 7,
283 WISPR_ELEMENT_NEXT_URL = 8,
284 WISPR_ELEMENT_DELAY = 9,
285 WISPR_ELEMENT_REPLY_MESSAGE = 10,
286 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
287 WISPR_ELEMENT_LOGOFF_URL = 12,
289 } wispr_element_map[] = {
290 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
291 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
292 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
293 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
294 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
295 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
296 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
297 { "NextURL", WISPR_ELEMENT_NEXT_URL },
298 { "Delay", WISPR_ELEMENT_DELAY },
299 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
300 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
301 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
302 { NULL, WISPR_ELEMENT_NONE },
305 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
306 const gchar *element_name,
307 const gchar **attribute_names,
308 const gchar **attribute_values,
309 gpointer user_data, GError **error)
311 struct connman_wispr_message *msg = user_data;
313 msg->current_element = element_name;
316 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
317 const gchar *element_name,
318 gpointer user_data, GError **error)
320 struct connman_wispr_message *msg = user_data;
322 msg->current_element = NULL;
325 static void xml_wispr_text_handler(GMarkupParseContext *context,
326 const gchar *text, gsize text_len,
327 gpointer user_data, GError **error)
329 struct connman_wispr_message *msg = user_data;
332 if (!msg->current_element)
335 for (i = 0; wispr_element_map[i].str; i++) {
336 if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
339 switch (wispr_element_map[i].element) {
340 case WISPR_ELEMENT_NONE:
341 case WISPR_ELEMENT_ACCESS_PROCEDURE:
342 g_free(msg->access_procedure);
343 msg->access_procedure = g_strdup(text);
345 case WISPR_ELEMENT_ACCESS_LOCATION:
346 g_free(msg->access_location);
347 msg->access_location = g_strdup(text);
349 case WISPR_ELEMENT_LOCATION_NAME:
350 g_free(msg->location_name);
351 msg->location_name = g_strdup(text);
353 case WISPR_ELEMENT_LOGIN_URL:
354 g_free(msg->login_url);
355 msg->login_url = g_strdup(text);
357 case WISPR_ELEMENT_ABORT_LOGIN_URL:
358 g_free(msg->abort_login_url);
359 msg->abort_login_url = g_strdup(text);
361 case WISPR_ELEMENT_MESSAGE_TYPE:
362 msg->message_type = atoi(text);
364 case WISPR_ELEMENT_RESPONSE_CODE:
365 msg->response_code = atoi(text);
367 case WISPR_ELEMENT_NEXT_URL:
368 case WISPR_ELEMENT_DELAY:
369 case WISPR_ELEMENT_REPLY_MESSAGE:
370 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
372 case WISPR_ELEMENT_LOGOFF_URL:
373 g_free(msg->logoff_url);
374 msg->logoff_url = g_strdup(text);
380 static void xml_wispr_error_handler(GMarkupParseContext *context,
381 GError *error, gpointer user_data)
383 struct connman_wispr_message *msg = user_data;
385 msg->has_error = true;
388 static const GMarkupParser xml_wispr_parser_handlers = {
389 xml_wispr_start_element_handler,
390 xml_wispr_end_element_handler,
391 xml_wispr_text_handler,
393 xml_wispr_error_handler,
396 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
398 struct connman_wispr_portal_context *wp_context = user_data;
399 GMarkupParseContext *parser_context = NULL;
404 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
405 G_MARKUP_TREAT_CDATA_AS_TEXT,
406 &(wp_context->wispr_msg), NULL);
408 result = g_markup_parse_context_parse(parser_context,
409 str, strlen(str), NULL);
411 g_markup_parse_context_end_parse(parser_context, NULL);
413 g_markup_parse_context_free(parser_context);
416 static void web_debug(const char *str, void *data)
418 connman_info("%s: %s\n", (const char *) data, str);
421 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
423 DBG("Failed to proceed wispr/portal web request");
425 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
427 #if defined TIZEN_EXT
428 connman_service_set_internet_connection(wp_context->service, false);
432 static void portal_manage_status(GWebResult *result,
433 struct connman_wispr_portal_context *wp_context)
435 struct connman_service *service = wp_context->service;
436 enum connman_ipconfig_type type = wp_context->type;
437 const char *str = NULL;
441 /* We currently don't do anything with this info */
442 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
444 connman_info("Client-IP: %s", str);
446 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
448 connman_info("Client-Country: %s", str);
450 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
452 connman_info("Client-Region: %s", str);
454 if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
456 connman_info("Client-Timezone: %s", str);
458 if (!enable_online_to_ready_transition)
459 free_connman_wispr_portal_context(wp_context);
461 __connman_service_ipconfig_indicate_state(service,
462 CONNMAN_SERVICE_STATE_ONLINE, type);
464 if (enable_online_to_ready_transition)
465 __connman_service_online_check(service, type, true);
468 static bool wispr_route_request(const char *address, int ai_family,
469 int if_index, gpointer user_data)
472 struct connman_wispr_portal_context *wp_context = user_data;
474 struct wispr_route *route;
476 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
479 DBG("address %s if %d gw %s", address, if_index, gateway);
484 route = g_try_new0(struct wispr_route, 1);
486 DBG("could not create struct");
490 switch (wp_context->type) {
491 case CONNMAN_IPCONFIG_TYPE_IPV4:
492 result = connman_inet_add_host_route(if_index, address,
495 case CONNMAN_IPCONFIG_TYPE_IPV6:
496 result = connman_inet_add_ipv6_host_route(if_index, address,
499 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
500 case CONNMAN_IPCONFIG_TYPE_ALL:
509 route->address = g_strdup(address);
510 route->if_index = if_index;
511 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
516 static void wispr_portal_request_portal(
517 struct connman_wispr_portal_context *wp_context)
521 wp_context->request_id = g_web_request_get(wp_context->web,
522 wp_context->status_url,
523 wispr_portal_web_result,
527 if (wp_context->request_id == 0)
528 wispr_portal_error(wp_context);
531 static bool wispr_input(const guint8 **data, gsize *length,
534 struct connman_wispr_portal_context *wp_context = user_data;
540 buf = g_string_sized_new(100);
542 g_string_append(buf, "button=Login&UserName=");
543 g_string_append_uri_escaped(buf, wp_context->wispr_username,
545 g_string_append(buf, "&Password=");
546 g_string_append_uri_escaped(buf, wp_context->wispr_password,
548 g_string_append(buf, "&FNAME=0&OriginatingServer=");
549 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
553 g_free(wp_context->wispr_formdata);
554 wp_context->wispr_formdata = g_string_free(buf, FALSE);
556 *data = (guint8 *) wp_context->wispr_formdata;
562 static void wispr_portal_browser_reply_cb(struct connman_service *service,
563 bool authentication_done,
564 const char *error, void *user_data)
566 struct connman_wispr_portal_context *wp_context = user_data;
567 struct connman_wispr_portal *wispr_portal;
572 if (!service || !wp_context)
576 * No way to cancel this if wp_context has been freed, so we lookup
577 * from the service and check that this is still the right context.
579 index = __connman_service_get_index(service);
583 wispr_portal = g_hash_table_lookup(wispr_portal_list,
584 GINT_TO_POINTER(index));
588 if (wp_context != wispr_portal->ipv4_context &&
589 wp_context != wispr_portal->ipv6_context)
592 if (!authentication_done) {
593 wispr_portal_error(wp_context);
594 free_wispr_routes(wp_context);
598 /* Restarting the test */
599 __connman_service_wispr_start(service, wp_context->type);
602 static void wispr_portal_request_wispr_login(struct connman_service *service,
604 const char *ssid, int ssid_len,
605 const char *username, const char *password,
606 bool wps, const char *wpspin,
607 const char *error, void *user_data)
609 struct connman_wispr_portal_context *wp_context = user_data;
615 "net.connman.Agent.Error.LaunchBrowser") == 0) {
616 if (__connman_agent_request_browser(service,
617 wispr_portal_browser_reply_cb,
618 wp_context->redirect_url,
619 wp_context) == -EINPROGRESS)
623 free_connman_wispr_portal_context(wp_context);
627 g_free(wp_context->wispr_username);
628 wp_context->wispr_username = g_strdup(username);
630 g_free(wp_context->wispr_password);
631 wp_context->wispr_password = g_strdup(password);
633 wp_context->request_id = g_web_request_post(wp_context->web,
634 wp_context->wispr_msg.login_url,
635 "application/x-www-form-urlencoded",
636 wispr_input, wispr_portal_web_result,
639 connman_wispr_message_init(&wp_context->wispr_msg);
642 static bool wispr_manage_message(GWebResult *result,
643 struct connman_wispr_portal_context *wp_context)
645 DBG("Message type: %s (%d)",
646 message_type_to_string(wp_context->wispr_msg.message_type),
647 wp_context->wispr_msg.message_type);
648 DBG("Response code: %s (%d)",
649 response_code_to_string(wp_context->wispr_msg.response_code),
650 wp_context->wispr_msg.response_code);
652 if (wp_context->wispr_msg.access_procedure)
653 DBG("Access procedure: %s",
654 wp_context->wispr_msg.access_procedure);
655 if (wp_context->wispr_msg.access_location)
656 DBG("Access location: %s",
657 wp_context->wispr_msg.access_location);
658 if (wp_context->wispr_msg.location_name)
659 DBG("Location name: %s",
660 wp_context->wispr_msg.location_name);
661 if (wp_context->wispr_msg.login_url)
662 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
663 if (wp_context->wispr_msg.abort_login_url)
664 DBG("Abort login URL: %s",
665 wp_context->wispr_msg.abort_login_url);
666 if (wp_context->wispr_msg.logoff_url)
667 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
669 switch (wp_context->wispr_msg.message_type) {
671 DBG("Login required");
673 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
675 if (__connman_agent_request_login_input(wp_context->service,
676 wispr_portal_request_wispr_login,
677 wp_context) != -EINPROGRESS)
678 wispr_portal_error(wp_context);
683 case 120: /* Falling down */
685 if (wp_context->wispr_msg.response_code == 50) {
686 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
688 g_free(wp_context->wispr_username);
689 wp_context->wispr_username = NULL;
691 g_free(wp_context->wispr_password);
692 wp_context->wispr_password = NULL;
694 g_free(wp_context->wispr_formdata);
695 wp_context->wispr_formdata = NULL;
697 wispr_portal_request_portal(wp_context);
701 wispr_portal_error(wp_context);
711 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
713 struct connman_wispr_portal_context *wp_context = user_data;
714 const char *redirect = NULL;
715 const guint8 *chunk = NULL;
716 const char *str = NULL;
719 #if defined TIZEN_MAINTAIN_ONLINE
720 static int retried = 0;
725 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
726 g_web_result_get_chunk(result, &chunk, &length);
729 g_web_parser_feed_data(wp_context->wispr_parser,
734 g_web_parser_end_data(wp_context->wispr_parser);
736 if (wp_context->wispr_msg.message_type >= 0) {
737 if (wispr_manage_message(result, wp_context))
742 status = g_web_result_get_status(result);
744 DBG("status: %03u", status);
748 __connman_agent_request_browser(wp_context->service,
749 wispr_portal_browser_reply_cb,
750 wp_context->status_url, wp_context);
753 #if defined TIZEN_MAINTAIN_ONLINE
756 if (wp_context->wispr_msg.message_type >= 0)
759 if (g_web_result_get_header(result, "X-ConnMan-Status",
761 portal_manage_status(result, wp_context);
764 __connman_agent_request_browser(wp_context->service,
765 wispr_portal_browser_reply_cb,
766 wp_context->redirect_url, wp_context);
775 if (!g_web_supports_tls() ||
776 !g_web_result_get_header(result, "Location",
779 __connman_agent_request_browser(wp_context->service,
780 wispr_portal_browser_reply_cb,
781 wp_context->status_url, wp_context);
785 DBG("Redirect URL: %s", redirect);
787 wp_context->redirect_url = g_strdup(redirect);
789 wp_context->request_id = g_web_request_get(wp_context->web,
790 redirect, wispr_portal_web_result,
791 wispr_route_request, wp_context);
796 __connman_service_online_check(wp_context->service,
797 wp_context->type, false);
798 #if defined TIZEN_MAINTAIN_ONLINE
799 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
801 connman_agent_report_error(wp_context->service,
802 __connman_service_get_path(wp_context->service),
803 "internet-unreachable",
813 __connman_agent_request_browser(wp_context->service,
814 wispr_portal_browser_reply_cb,
815 wp_context->status_url, wp_context);
821 free_wispr_routes(wp_context);
822 wp_context->request_id = 0;
824 wp_context->wispr_msg.message_type = -1;
828 static void proxy_callback(const char *proxy, void *user_data)
830 struct connman_wispr_portal_context *wp_context = user_data;
832 DBG("proxy %s", proxy);
837 wp_context->token = 0;
839 if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
840 if (g_str_has_prefix(proxy, "PROXY")) {
842 for (; *proxy == ' ' && *proxy != '\0'; proxy++);
844 g_web_set_proxy(wp_context->web, proxy);
847 g_web_set_accept(wp_context->web, NULL);
848 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
849 g_web_set_close_connection(wp_context->web, TRUE);
851 connman_wispr_message_init(&wp_context->wispr_msg);
853 wp_context->wispr_parser = g_web_parser_new(
854 "<WISPAccessGatewayParam",
855 "WISPAccessGatewayParam>",
856 xml_wispr_parser_callback, wp_context);
858 wispr_portal_request_portal(wp_context);
861 static gboolean no_proxy_callback(gpointer user_data)
863 struct connman_wispr_portal_context *wp_context = user_data;
865 wp_context->timeout = 0;
867 proxy_callback("DIRECT", wp_context);
872 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
874 enum connman_service_proxy_method proxy_method;
875 enum connman_service_type service_type;
876 char *interface = NULL;
877 char **nameservers = NULL;
882 DBG("wispr/portal context %p service %p", wp_context,
883 wp_context->service);
885 service_type = connman_service_get_type(wp_context->service);
887 switch (service_type) {
888 case CONNMAN_SERVICE_TYPE_ETHERNET:
889 case CONNMAN_SERVICE_TYPE_WIFI:
890 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
891 case CONNMAN_SERVICE_TYPE_CELLULAR:
892 case CONNMAN_SERVICE_TYPE_GADGET:
894 case CONNMAN_SERVICE_TYPE_UNKNOWN:
895 case CONNMAN_SERVICE_TYPE_SYSTEM:
896 case CONNMAN_SERVICE_TYPE_GPS:
897 case CONNMAN_SERVICE_TYPE_VPN:
898 case CONNMAN_SERVICE_TYPE_P2P:
899 #if defined TIZEN_EXT_WIFI_MESH
900 case CONNMAN_SERVICE_TYPE_MESH:
905 interface = connman_service_get_interface(wp_context->service);
909 DBG("interface %s", interface);
911 if_index = connman_inet_ifindex(interface);
913 DBG("Could not get ifindex");
918 nameservers = connman_service_get_nameservers(wp_context->service);
920 DBG("Could not get nameservers");
925 wp_context->web = g_web_new(if_index);
926 if (!wp_context->web) {
927 DBG("Could not set up GWeb");
932 #if !defined TIZEN_EXT
933 if (getenv("CONNMAN_WEB_DEBUG"))
935 g_web_set_debug(wp_context->web, web_debug, "WEB");
937 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
938 g_web_set_address_family(wp_context->web, AF_INET);
939 wp_context->status_url = online_check_ipv4_url;
941 g_web_set_address_family(wp_context->web, AF_INET6);
942 wp_context->status_url = online_check_ipv6_url;
945 for (i = 0; nameservers[i]; i++)
946 g_web_add_nameserver(wp_context->web, nameservers[i]);
948 proxy_method = connman_service_get_proxy_method(wp_context->service);
950 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
951 wp_context->token = connman_proxy_lookup(interface,
952 wp_context->status_url,
954 proxy_callback, wp_context);
956 if (wp_context->token == 0) {
958 free_connman_wispr_portal_context(wp_context);
960 } else if (wp_context->timeout == 0) {
961 wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
965 g_strfreev(nameservers);
971 int __connman_wispr_start(struct connman_service *service,
972 enum connman_ipconfig_type type)
974 struct connman_wispr_portal_context *wp_context = NULL;
975 struct connman_wispr_portal *wispr_portal = NULL;
978 DBG("service %p", service);
980 #if defined TIZEN_EXT
981 if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_CELLULAR)
985 if (!wispr_portal_list)
988 index = __connman_service_get_index(service);
992 wispr_portal = g_hash_table_lookup(wispr_portal_list,
993 GINT_TO_POINTER(index));
995 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
999 g_hash_table_replace(wispr_portal_list,
1000 GINT_TO_POINTER(index), wispr_portal);
1003 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1004 wp_context = wispr_portal->ipv4_context;
1005 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1006 wp_context = wispr_portal->ipv6_context;
1010 /* If there is already an existing context, we wipe it */
1012 free_connman_wispr_portal_context(wp_context);
1014 wp_context = create_wispr_portal_context();
1018 wp_context->service = service;
1019 wp_context->type = type;
1020 wp_context->wispr_portal = wispr_portal;
1022 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1023 wispr_portal->ipv4_context = wp_context;
1025 wispr_portal->ipv6_context = wp_context;
1027 return wispr_portal_detect(wp_context);
1030 void __connman_wispr_stop(struct connman_service *service)
1032 struct connman_wispr_portal *wispr_portal;
1035 DBG("service %p", service);
1037 if (!wispr_portal_list)
1040 index = __connman_service_get_index(service);
1044 wispr_portal = g_hash_table_lookup(wispr_portal_list,
1045 GINT_TO_POINTER(index));
1049 if ((wispr_portal->ipv4_context &&
1050 service == wispr_portal->ipv4_context->service) ||
1051 (wispr_portal->ipv6_context &&
1052 service == wispr_portal->ipv6_context->service))
1053 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1056 int __connman_wispr_init(void)
1060 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1061 g_direct_equal, NULL,
1062 free_connman_wispr_portal);
1064 online_check_ipv4_url =
1065 connman_setting_get_string("OnlineCheckIPv4URL");
1066 online_check_ipv6_url =
1067 connman_setting_get_string("OnlineCheckIPv6URL");
1069 enable_online_to_ready_transition =
1070 connman_setting_get_bool("EnableOnlineToReadyTransition");
1075 void __connman_wispr_cleanup(void)
1079 g_hash_table_destroy(wispr_portal_list);
1080 wispr_portal_list = NULL;