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 #define STATUS_URL_IPV4 "http://ipv4.connman.net/online/status.html"
34 #define STATUS_URL_IPV6 "http://ipv6.connman.net/online/status.html"
36 struct connman_wispr_message {
38 const char *current_element;
42 char *abort_login_url;
44 char *access_procedure;
45 char *access_location;
49 enum connman_wispr_result {
50 CONNMAN_WISPR_RESULT_UNKNOWN = 0,
51 CONNMAN_WISPR_RESULT_LOGIN = 1,
52 CONNMAN_WISPR_RESULT_ONLINE = 2,
53 CONNMAN_WISPR_RESULT_FAILED = 3,
61 struct connman_wispr_portal_context {
62 struct connman_service *service;
63 enum connman_ipconfig_type type;
64 struct connman_wispr_portal *wispr_portal;
66 /* Portal/WISPr common */
71 const char *status_url;
76 GWebParser *wispr_parser;
77 struct connman_wispr_message wispr_msg;
83 enum connman_wispr_result wispr_result;
90 struct connman_wispr_portal {
91 struct connman_wispr_portal_context *ipv4_context;
92 struct connman_wispr_portal_context *ipv6_context;
95 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
97 static GHashTable *wispr_portal_list = NULL;
99 static bool enable_online_to_ready_transition = false;
101 static void connman_wispr_message_init(struct connman_wispr_message *msg)
105 msg->has_error = false;
106 msg->current_element = NULL;
108 msg->message_type = -1;
109 msg->response_code = -1;
111 g_free(msg->login_url);
112 msg->login_url = NULL;
114 g_free(msg->abort_login_url);
115 msg->abort_login_url = NULL;
117 g_free(msg->logoff_url);
118 msg->logoff_url = NULL;
120 g_free(msg->access_procedure);
121 msg->access_procedure = NULL;
123 g_free(msg->access_location);
124 msg->access_location = NULL;
126 g_free(msg->location_name);
127 msg->location_name = NULL;
130 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
132 while (wp_context->route_list) {
133 struct wispr_route *route = wp_context->route_list->data;
135 DBG("free route to %s if %d type %d", route->address,
136 route->if_index, wp_context->type);
138 switch (wp_context->type) {
139 case CONNMAN_IPCONFIG_TYPE_IPV4:
140 connman_inet_del_host_route(route->if_index,
143 case CONNMAN_IPCONFIG_TYPE_IPV6:
144 connman_inet_del_ipv6_host_route(route->if_index,
147 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
148 case CONNMAN_IPCONFIG_TYPE_ALL:
152 g_free(route->address);
155 wp_context->route_list =
156 g_slist_delete_link(wp_context->route_list,
157 wp_context->route_list);
161 static void free_connman_wispr_portal_context(
162 struct connman_wispr_portal_context *wp_context)
164 DBG("context %p", wp_context);
169 if (wp_context->wispr_portal) {
170 if (wp_context->wispr_portal->ipv4_context == wp_context)
171 wp_context->wispr_portal->ipv4_context = NULL;
173 if (wp_context->wispr_portal->ipv6_context == wp_context)
174 wp_context->wispr_portal->ipv6_context = NULL;
177 if (wp_context->token > 0)
178 connman_proxy_lookup_cancel(wp_context->token);
180 if (wp_context->request_id > 0)
181 g_web_cancel_request(wp_context->web, wp_context->request_id);
183 if (wp_context->timeout > 0)
184 g_source_remove(wp_context->timeout);
187 g_web_unref(wp_context->web);
189 g_free(wp_context->redirect_url);
191 if (wp_context->wispr_parser)
192 g_web_parser_unref(wp_context->wispr_parser);
194 connman_wispr_message_init(&wp_context->wispr_msg);
196 g_free(wp_context->wispr_username);
197 g_free(wp_context->wispr_password);
198 g_free(wp_context->wispr_formdata);
200 free_wispr_routes(wp_context);
205 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
207 return g_try_new0(struct connman_wispr_portal_context, 1);
210 static void free_connman_wispr_portal(gpointer data)
212 struct connman_wispr_portal *wispr_portal = data;
219 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
220 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
222 g_free(wispr_portal);
225 static const char *message_type_to_string(int message_type)
227 switch (message_type) {
229 return "Initial redirect message";
231 return "Proxy notification";
233 return "Authentication notification";
235 return "Logoff notification";
237 return "Response to Authentication Poll";
239 return "Response to Abort Login";
245 static const char *response_code_to_string(int response_code)
247 switch (response_code) {
251 return "Login succeeded";
253 return "Login failed";
255 return "RADIUS server error/timeout";
257 return "RADIUS server not enabled";
259 return "Logoff succeeded";
261 return "Login aborted";
263 return "Proxy detection/repeat operation";
265 return "Authentication pending";
267 return "Access gateway internal error";
276 WISPR_ELEMENT_NONE = 0,
277 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
278 WISPR_ELEMENT_ACCESS_LOCATION = 2,
279 WISPR_ELEMENT_LOCATION_NAME = 3,
280 WISPR_ELEMENT_LOGIN_URL = 4,
281 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
282 WISPR_ELEMENT_MESSAGE_TYPE = 6,
283 WISPR_ELEMENT_RESPONSE_CODE = 7,
284 WISPR_ELEMENT_NEXT_URL = 8,
285 WISPR_ELEMENT_DELAY = 9,
286 WISPR_ELEMENT_REPLY_MESSAGE = 10,
287 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
288 WISPR_ELEMENT_LOGOFF_URL = 12,
290 } wispr_element_map[] = {
291 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
292 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
293 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
294 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
295 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
296 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
297 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
298 { "NextURL", WISPR_ELEMENT_NEXT_URL },
299 { "Delay", WISPR_ELEMENT_DELAY },
300 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
301 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
302 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
303 { NULL, WISPR_ELEMENT_NONE },
306 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
307 const gchar *element_name,
308 const gchar **attribute_names,
309 const gchar **attribute_values,
310 gpointer user_data, GError **error)
312 struct connman_wispr_message *msg = user_data;
314 msg->current_element = element_name;
317 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
318 const gchar *element_name,
319 gpointer user_data, GError **error)
321 struct connman_wispr_message *msg = user_data;
323 msg->current_element = NULL;
326 static void xml_wispr_text_handler(GMarkupParseContext *context,
327 const gchar *text, gsize text_len,
328 gpointer user_data, GError **error)
330 struct connman_wispr_message *msg = user_data;
333 if (!msg->current_element)
336 for (i = 0; wispr_element_map[i].str; i++) {
337 if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
340 switch (wispr_element_map[i].element) {
341 case WISPR_ELEMENT_NONE:
342 case WISPR_ELEMENT_ACCESS_PROCEDURE:
343 g_free(msg->access_procedure);
344 msg->access_procedure = g_strdup(text);
346 case WISPR_ELEMENT_ACCESS_LOCATION:
347 g_free(msg->access_location);
348 msg->access_location = g_strdup(text);
350 case WISPR_ELEMENT_LOCATION_NAME:
351 g_free(msg->location_name);
352 msg->location_name = g_strdup(text);
354 case WISPR_ELEMENT_LOGIN_URL:
355 g_free(msg->login_url);
356 msg->login_url = g_strdup(text);
358 case WISPR_ELEMENT_ABORT_LOGIN_URL:
359 g_free(msg->abort_login_url);
360 msg->abort_login_url = g_strdup(text);
362 case WISPR_ELEMENT_MESSAGE_TYPE:
363 msg->message_type = atoi(text);
365 case WISPR_ELEMENT_RESPONSE_CODE:
366 msg->response_code = atoi(text);
368 case WISPR_ELEMENT_NEXT_URL:
369 case WISPR_ELEMENT_DELAY:
370 case WISPR_ELEMENT_REPLY_MESSAGE:
371 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
373 case WISPR_ELEMENT_LOGOFF_URL:
374 g_free(msg->logoff_url);
375 msg->logoff_url = g_strdup(text);
381 static void xml_wispr_error_handler(GMarkupParseContext *context,
382 GError *error, gpointer user_data)
384 struct connman_wispr_message *msg = user_data;
386 msg->has_error = true;
389 static const GMarkupParser xml_wispr_parser_handlers = {
390 xml_wispr_start_element_handler,
391 xml_wispr_end_element_handler,
392 xml_wispr_text_handler,
394 xml_wispr_error_handler,
397 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
399 struct connman_wispr_portal_context *wp_context = user_data;
400 GMarkupParseContext *parser_context = NULL;
405 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
406 G_MARKUP_TREAT_CDATA_AS_TEXT,
407 &(wp_context->wispr_msg), NULL);
409 result = g_markup_parse_context_parse(parser_context,
410 str, strlen(str), NULL);
412 g_markup_parse_context_end_parse(parser_context, NULL);
414 g_markup_parse_context_free(parser_context);
417 static void web_debug(const char *str, void *data)
419 connman_info("%s: %s\n", (const char *) data, str);
422 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
424 DBG("Failed to proceed wispr/portal web request");
426 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
428 #if defined TIZEN_EXT
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 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
850 g_web_set_close_connection(wp_context->web, TRUE);
852 connman_wispr_message_init(&wp_context->wispr_msg);
854 wp_context->wispr_parser = g_web_parser_new(
855 "<WISPAccessGatewayParam",
856 "WISPAccessGatewayParam>",
857 xml_wispr_parser_callback, wp_context);
859 wispr_portal_request_portal(wp_context);
862 static gboolean no_proxy_callback(gpointer user_data)
864 struct connman_wispr_portal_context *wp_context = user_data;
866 wp_context->timeout = 0;
868 proxy_callback("DIRECT", wp_context);
873 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
875 enum connman_service_proxy_method proxy_method;
876 enum connman_service_type service_type;
877 char *interface = NULL;
878 char **nameservers = NULL;
883 DBG("wispr/portal context %p service %p", wp_context,
884 wp_context->service);
886 service_type = connman_service_get_type(wp_context->service);
888 switch (service_type) {
889 case CONNMAN_SERVICE_TYPE_ETHERNET:
890 case CONNMAN_SERVICE_TYPE_WIFI:
891 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
892 case CONNMAN_SERVICE_TYPE_CELLULAR:
893 case CONNMAN_SERVICE_TYPE_GADGET:
895 case CONNMAN_SERVICE_TYPE_UNKNOWN:
896 case CONNMAN_SERVICE_TYPE_SYSTEM:
897 case CONNMAN_SERVICE_TYPE_GPS:
898 case CONNMAN_SERVICE_TYPE_VPN:
899 case CONNMAN_SERVICE_TYPE_P2P:
900 #if defined TIZEN_EXT_WIFI_MESH
901 case CONNMAN_SERVICE_TYPE_MESH:
906 interface = connman_service_get_interface(wp_context->service);
910 DBG("interface %s", interface);
912 if_index = connman_inet_ifindex(interface);
914 DBG("Could not get ifindex");
919 nameservers = connman_service_get_nameservers(wp_context->service);
921 DBG("Could not get nameservers");
926 wp_context->web = g_web_new(if_index);
927 if (!wp_context->web) {
928 DBG("Could not set up GWeb");
933 #if !defined TIZEN_EXT
934 if (getenv("CONNMAN_WEB_DEBUG"))
936 g_web_set_debug(wp_context->web, web_debug, "WEB");
938 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
939 g_web_set_address_family(wp_context->web, AF_INET);
940 wp_context->status_url = STATUS_URL_IPV4;
942 g_web_set_address_family(wp_context->web, AF_INET6);
943 wp_context->status_url = STATUS_URL_IPV6;
946 for (i = 0; nameservers[i]; i++)
947 g_web_add_nameserver(wp_context->web, nameservers[i]);
949 proxy_method = connman_service_get_proxy_method(wp_context->service);
951 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
952 wp_context->token = connman_proxy_lookup(interface,
953 wp_context->status_url,
955 proxy_callback, wp_context);
957 if (wp_context->token == 0) {
959 free_connman_wispr_portal_context(wp_context);
961 } else if (wp_context->timeout == 0) {
962 wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
966 g_strfreev(nameservers);
972 int __connman_wispr_start(struct connman_service *service,
973 enum connman_ipconfig_type type)
975 struct connman_wispr_portal_context *wp_context = NULL;
976 struct connman_wispr_portal *wispr_portal = NULL;
979 DBG("service %p", service);
981 #if defined TIZEN_EXT
982 if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_CELLULAR)
986 if (!wispr_portal_list)
989 index = __connman_service_get_index(service);
993 wispr_portal = g_hash_table_lookup(wispr_portal_list,
994 GINT_TO_POINTER(index));
996 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
1000 g_hash_table_replace(wispr_portal_list,
1001 GINT_TO_POINTER(index), wispr_portal);
1004 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1005 wp_context = wispr_portal->ipv4_context;
1006 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1007 wp_context = wispr_portal->ipv6_context;
1011 /* If there is already an existing context, we wipe it */
1013 free_connman_wispr_portal_context(wp_context);
1015 wp_context = create_wispr_portal_context();
1019 wp_context->service = service;
1020 wp_context->type = type;
1021 wp_context->wispr_portal = wispr_portal;
1023 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1024 wispr_portal->ipv4_context = wp_context;
1026 wispr_portal->ipv6_context = wp_context;
1028 return wispr_portal_detect(wp_context);
1031 void __connman_wispr_stop(struct connman_service *service)
1033 struct connman_wispr_portal *wispr_portal;
1036 DBG("service %p", service);
1038 if (!wispr_portal_list)
1041 index = __connman_service_get_index(service);
1045 wispr_portal = g_hash_table_lookup(wispr_portal_list,
1046 GINT_TO_POINTER(index));
1050 if ((wispr_portal->ipv4_context &&
1051 service == wispr_portal->ipv4_context->service) ||
1052 (wispr_portal->ipv6_context &&
1053 service == wispr_portal->ipv6_context->service))
1054 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
1057 int __connman_wispr_init(void)
1061 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1062 g_direct_equal, NULL,
1063 free_connman_wispr_portal);
1065 enable_online_to_ready_transition =
1066 connman_setting_get_bool("EnableOnlineToReadyTransition");
1071 void __connman_wispr_cleanup(void)
1075 g_hash_table_destroy(wispr_portal_list);
1076 wispr_portal_list = NULL;