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 if (TIZEN_INS_ENABLED)
429 connman_service_set_internet_connection(wp_context->service, false);
433 static void portal_manage_status(GWebResult *result,
434 struct connman_wispr_portal_context *wp_context)
436 struct connman_service *service = wp_context->service;
437 enum connman_ipconfig_type type = wp_context->type;
438 const char *str = NULL;
442 /* We currently don't do anything with this info */
443 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
445 connman_info("Client-IP: %s", str);
447 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
449 connman_info("Client-Country: %s", str);
451 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
453 connman_info("Client-Region: %s", str);
455 if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
457 connman_info("Client-Timezone: %s", str);
459 if (!enable_online_to_ready_transition)
460 free_connman_wispr_portal_context(wp_context);
462 __connman_service_ipconfig_indicate_state(service,
463 CONNMAN_SERVICE_STATE_ONLINE, type);
465 if (enable_online_to_ready_transition)
466 __connman_service_online_check(service, type, true);
469 static bool wispr_route_request(const char *address, int ai_family,
470 int if_index, gpointer user_data)
473 struct connman_wispr_portal_context *wp_context = user_data;
475 struct wispr_route *route;
477 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
480 DBG("address %s if %d gw %s", address, if_index, gateway);
485 route = g_try_new0(struct wispr_route, 1);
487 DBG("could not create struct");
491 switch (wp_context->type) {
492 case CONNMAN_IPCONFIG_TYPE_IPV4:
493 result = connman_inet_add_host_route(if_index, address,
496 case CONNMAN_IPCONFIG_TYPE_IPV6:
497 result = connman_inet_add_ipv6_host_route(if_index, address,
500 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
501 case CONNMAN_IPCONFIG_TYPE_ALL:
510 route->address = g_strdup(address);
511 route->if_index = if_index;
512 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
517 static void wispr_portal_request_portal(
518 struct connman_wispr_portal_context *wp_context)
522 wp_context->request_id = g_web_request_get(wp_context->web,
523 wp_context->status_url,
524 wispr_portal_web_result,
528 if (wp_context->request_id == 0)
529 wispr_portal_error(wp_context);
532 static bool wispr_input(const guint8 **data, gsize *length,
535 struct connman_wispr_portal_context *wp_context = user_data;
541 buf = g_string_sized_new(100);
543 g_string_append(buf, "button=Login&UserName=");
544 g_string_append_uri_escaped(buf, wp_context->wispr_username,
546 g_string_append(buf, "&Password=");
547 g_string_append_uri_escaped(buf, wp_context->wispr_password,
549 g_string_append(buf, "&FNAME=0&OriginatingServer=");
550 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
554 g_free(wp_context->wispr_formdata);
555 wp_context->wispr_formdata = g_string_free(buf, FALSE);
557 *data = (guint8 *) wp_context->wispr_formdata;
563 static void wispr_portal_browser_reply_cb(struct connman_service *service,
564 bool authentication_done,
565 const char *error, void *user_data)
567 struct connman_wispr_portal_context *wp_context = user_data;
568 struct connman_wispr_portal *wispr_portal;
573 if (!service || !wp_context)
577 * No way to cancel this if wp_context has been freed, so we lookup
578 * from the service and check that this is still the right context.
580 index = __connman_service_get_index(service);
584 wispr_portal = g_hash_table_lookup(wispr_portal_list,
585 GINT_TO_POINTER(index));
589 if (wp_context != wispr_portal->ipv4_context &&
590 wp_context != wispr_portal->ipv6_context)
593 if (!authentication_done) {
594 wispr_portal_error(wp_context);
595 free_wispr_routes(wp_context);
599 /* Restarting the test */
600 __connman_service_wispr_start(service, wp_context->type);
603 static void wispr_portal_request_wispr_login(struct connman_service *service,
605 const char *ssid, int ssid_len,
606 const char *username, const char *password,
607 bool wps, const char *wpspin,
608 const char *error, void *user_data)
610 struct connman_wispr_portal_context *wp_context = user_data;
616 "net.connman.Agent.Error.LaunchBrowser") == 0) {
617 if (__connman_agent_request_browser(service,
618 wispr_portal_browser_reply_cb,
619 wp_context->redirect_url,
620 wp_context) == -EINPROGRESS)
624 free_connman_wispr_portal_context(wp_context);
628 g_free(wp_context->wispr_username);
629 wp_context->wispr_username = g_strdup(username);
631 g_free(wp_context->wispr_password);
632 wp_context->wispr_password = g_strdup(password);
634 wp_context->request_id = g_web_request_post(wp_context->web,
635 wp_context->wispr_msg.login_url,
636 "application/x-www-form-urlencoded",
637 wispr_input, wispr_portal_web_result,
640 connman_wispr_message_init(&wp_context->wispr_msg);
643 static bool wispr_manage_message(GWebResult *result,
644 struct connman_wispr_portal_context *wp_context)
646 DBG("Message type: %s (%d)",
647 message_type_to_string(wp_context->wispr_msg.message_type),
648 wp_context->wispr_msg.message_type);
649 DBG("Response code: %s (%d)",
650 response_code_to_string(wp_context->wispr_msg.response_code),
651 wp_context->wispr_msg.response_code);
653 if (wp_context->wispr_msg.access_procedure)
654 DBG("Access procedure: %s",
655 wp_context->wispr_msg.access_procedure);
656 if (wp_context->wispr_msg.access_location)
657 DBG("Access location: %s",
658 wp_context->wispr_msg.access_location);
659 if (wp_context->wispr_msg.location_name)
660 DBG("Location name: %s",
661 wp_context->wispr_msg.location_name);
662 if (wp_context->wispr_msg.login_url)
663 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
664 if (wp_context->wispr_msg.abort_login_url)
665 DBG("Abort login URL: %s",
666 wp_context->wispr_msg.abort_login_url);
667 if (wp_context->wispr_msg.logoff_url)
668 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
670 switch (wp_context->wispr_msg.message_type) {
672 DBG("Login required");
674 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
676 if (__connman_agent_request_login_input(wp_context->service,
677 wispr_portal_request_wispr_login,
678 wp_context) != -EINPROGRESS)
679 wispr_portal_error(wp_context);
684 case 120: /* Falling down */
686 if (wp_context->wispr_msg.response_code == 50) {
687 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
689 g_free(wp_context->wispr_username);
690 wp_context->wispr_username = NULL;
692 g_free(wp_context->wispr_password);
693 wp_context->wispr_password = NULL;
695 g_free(wp_context->wispr_formdata);
696 wp_context->wispr_formdata = NULL;
698 wispr_portal_request_portal(wp_context);
702 wispr_portal_error(wp_context);
712 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
714 struct connman_wispr_portal_context *wp_context = user_data;
715 const char *redirect = NULL;
716 const guint8 *chunk = NULL;
717 const char *str = NULL;
720 #if defined TIZEN_MAINTAIN_ONLINE
721 static int retried = 0;
726 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
727 g_web_result_get_chunk(result, &chunk, &length);
730 g_web_parser_feed_data(wp_context->wispr_parser,
735 g_web_parser_end_data(wp_context->wispr_parser);
737 if (wp_context->wispr_msg.message_type >= 0) {
738 if (wispr_manage_message(result, wp_context))
743 status = g_web_result_get_status(result);
745 DBG("status: %03u", status);
749 __connman_agent_request_browser(wp_context->service,
750 wispr_portal_browser_reply_cb,
751 wp_context->status_url, wp_context);
754 #if defined TIZEN_MAINTAIN_ONLINE
757 if (wp_context->wispr_msg.message_type >= 0)
760 if (g_web_result_get_header(result, "X-ConnMan-Status",
762 portal_manage_status(result, wp_context);
765 __connman_agent_request_browser(wp_context->service,
766 wispr_portal_browser_reply_cb,
767 wp_context->redirect_url, wp_context);
776 if (!g_web_supports_tls() ||
777 !g_web_result_get_header(result, "Location",
780 __connman_agent_request_browser(wp_context->service,
781 wispr_portal_browser_reply_cb,
782 wp_context->status_url, wp_context);
786 DBG("Redirect URL: %s", redirect);
788 wp_context->redirect_url = g_strdup(redirect);
790 wp_context->request_id = g_web_request_get(wp_context->web,
791 redirect, wispr_portal_web_result,
792 wispr_route_request, wp_context);
797 __connman_service_online_check(wp_context->service,
798 wp_context->type, false);
799 #if defined TIZEN_MAINTAIN_ONLINE
800 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
802 connman_agent_report_error(wp_context->service,
803 __connman_service_get_path(wp_context->service),
804 "internet-unreachable",
814 __connman_agent_request_browser(wp_context->service,
815 wispr_portal_browser_reply_cb,
816 wp_context->status_url, wp_context);
822 free_wispr_routes(wp_context);
823 wp_context->request_id = 0;
825 wp_context->wispr_msg.message_type = -1;
829 static void proxy_callback(const char *proxy, void *user_data)
831 struct connman_wispr_portal_context *wp_context = user_data;
833 DBG("proxy %s", proxy);
838 wp_context->token = 0;
840 if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
841 if (g_str_has_prefix(proxy, "PROXY")) {
843 for (; *proxy == ' ' && *proxy != '\0'; proxy++);
845 g_web_set_proxy(wp_context->web, proxy);
848 g_web_set_accept(wp_context->web, NULL);
849 #if defined TIZEN_EXT
850 g_web_set_user_agent(wp_context->web, "Tizen");
852 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
854 g_web_set_close_connection(wp_context->web, TRUE);
856 connman_wispr_message_init(&wp_context->wispr_msg);
858 wp_context->wispr_parser = g_web_parser_new(
859 "<WISPAccessGatewayParam",
860 "WISPAccessGatewayParam>",
861 xml_wispr_parser_callback, wp_context);
863 wispr_portal_request_portal(wp_context);
866 static gboolean no_proxy_callback(gpointer user_data)
868 struct connman_wispr_portal_context *wp_context = user_data;
870 wp_context->timeout = 0;
872 proxy_callback("DIRECT", wp_context);
877 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
879 enum connman_service_proxy_method proxy_method;
880 enum connman_service_type service_type;
881 char *interface = NULL;
882 char **nameservers = NULL;
887 DBG("wispr/portal context %p service %p", wp_context,
888 wp_context->service);
890 service_type = connman_service_get_type(wp_context->service);
892 switch (service_type) {
893 case CONNMAN_SERVICE_TYPE_ETHERNET:
894 case CONNMAN_SERVICE_TYPE_WIFI:
895 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
896 case CONNMAN_SERVICE_TYPE_CELLULAR:
897 case CONNMAN_SERVICE_TYPE_GADGET:
899 case CONNMAN_SERVICE_TYPE_UNKNOWN:
900 case CONNMAN_SERVICE_TYPE_SYSTEM:
901 case CONNMAN_SERVICE_TYPE_GPS:
902 case CONNMAN_SERVICE_TYPE_VPN:
903 case CONNMAN_SERVICE_TYPE_P2P:
904 #if defined TIZEN_EXT_WIFI_MESH
905 case CONNMAN_SERVICE_TYPE_MESH:
910 interface = connman_service_get_interface(wp_context->service);
914 DBG("interface %s", interface);
916 if_index = connman_inet_ifindex(interface);
918 DBG("Could not get ifindex");
923 nameservers = connman_service_get_nameservers(wp_context->service);
925 DBG("Could not get nameservers");
930 wp_context->web = g_web_new(if_index);
931 if (!wp_context->web) {
932 DBG("Could not set up GWeb");
937 #if !defined TIZEN_EXT
938 if (getenv("CONNMAN_WEB_DEBUG"))
940 g_web_set_debug(wp_context->web, web_debug, "WEB");
942 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
943 g_web_set_address_family(wp_context->web, AF_INET);
944 wp_context->status_url = online_check_ipv4_url;
946 g_web_set_address_family(wp_context->web, AF_INET6);
947 wp_context->status_url = online_check_ipv6_url;
950 for (i = 0; nameservers[i]; i++)
951 g_web_add_nameserver(wp_context->web, nameservers[i]);
953 proxy_method = connman_service_get_proxy_method(wp_context->service);
955 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
956 wp_context->token = connman_proxy_lookup(interface,
957 wp_context->status_url,
959 proxy_callback, wp_context);
961 if (wp_context->token == 0) {
963 free_connman_wispr_portal_context(wp_context);
965 } else if (wp_context->timeout == 0) {
966 wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
970 g_strfreev(nameservers);
976 int __connman_wispr_start(struct connman_service *service,
977 enum connman_ipconfig_type type)
979 struct connman_wispr_portal_context *wp_context = NULL;
980 struct connman_wispr_portal *wispr_portal = NULL;
983 DBG("service %p", service);
985 #if defined TIZEN_EXT
986 if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_CELLULAR)
990 if (!wispr_portal_list)
993 index = __connman_service_get_index(service);
997 wispr_portal = g_hash_table_lookup(wispr_portal_list,
998 GINT_TO_POINTER(index));
1000 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
1004 g_hash_table_replace(wispr_portal_list,
1005 GINT_TO_POINTER(index), wispr_portal);
1008 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1009 wp_context = wispr_portal->ipv4_context;
1010 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1011 wp_context = wispr_portal->ipv6_context;
1015 /* If there is already an existing context, we wipe it */
1017 free_connman_wispr_portal_context(wp_context);
1019 wp_context = create_wispr_portal_context();
1023 wp_context->service = service;
1024 wp_context->type = type;
1025 wp_context->wispr_portal = wispr_portal;
1027 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1028 wispr_portal->ipv4_context = wp_context;
1030 wispr_portal->ipv6_context = wp_context;
1032 return wispr_portal_detect(wp_context);
1035 void __connman_wispr_stop(struct connman_service *service)
1037 struct connman_wispr_portal *wispr_portal;
1040 DBG("service %p", service);
1042 if (!wispr_portal_list)
1045 index = __connman_service_get_index(service);
1049 wispr_portal = g_hash_table_lookup(wispr_portal_list,
1050 GINT_TO_POINTER(index));
1054 if ((wispr_portal->ipv4_context &&
1055 service == wispr_portal->ipv4_context->service) ||
1056 (wispr_portal->ipv6_context &&
1057 service == wispr_portal->ipv6_context->service))
1058 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1061 int __connman_wispr_init(void)
1065 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1066 g_direct_equal, NULL,
1067 free_connman_wispr_portal);
1069 online_check_ipv4_url =
1070 connman_setting_get_string("OnlineCheckIPv4URL");
1071 online_check_ipv6_url =
1072 connman_setting_get_string("OnlineCheckIPv6URL");
1074 enable_online_to_ready_transition =
1075 connman_setting_get_bool("EnableOnlineToReadyTransition");
1080 void __connman_wispr_cleanup(void)
1084 g_hash_table_destroy(wispr_portal_list);
1085 wispr_portal_list = NULL;