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;
429 static void portal_manage_status(GWebResult *result,
430 struct connman_wispr_portal_context *wp_context)
432 struct connman_service *service = wp_context->service;
433 enum connman_ipconfig_type type = wp_context->type;
434 const char *str = NULL;
438 /* We currently don't do anything with this info */
439 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
441 connman_info("Client-IP: %s", str);
443 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
445 connman_info("Client-Country: %s", str);
447 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
449 connman_info("Client-Region: %s", str);
451 if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
453 connman_info("Client-Timezone: %s", str);
455 if (!enable_online_to_ready_transition)
456 free_connman_wispr_portal_context(wp_context);
458 __connman_service_ipconfig_indicate_state(service,
459 CONNMAN_SERVICE_STATE_ONLINE, type);
461 if (enable_online_to_ready_transition)
462 __connman_service_online_check(service, type, true);
465 static bool wispr_route_request(const char *address, int ai_family,
466 int if_index, gpointer user_data)
469 struct connman_wispr_portal_context *wp_context = user_data;
471 struct wispr_route *route;
473 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
476 DBG("address %s if %d gw %s", address, if_index, gateway);
481 route = g_try_new0(struct wispr_route, 1);
483 DBG("could not create struct");
487 switch (wp_context->type) {
488 case CONNMAN_IPCONFIG_TYPE_IPV4:
489 result = connman_inet_add_host_route(if_index, address,
492 case CONNMAN_IPCONFIG_TYPE_IPV6:
493 result = connman_inet_add_ipv6_host_route(if_index, address,
496 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
497 case CONNMAN_IPCONFIG_TYPE_ALL:
506 route->address = g_strdup(address);
507 route->if_index = if_index;
508 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
513 static void wispr_portal_request_portal(
514 struct connman_wispr_portal_context *wp_context)
518 wp_context->request_id = g_web_request_get(wp_context->web,
519 wp_context->status_url,
520 wispr_portal_web_result,
524 if (wp_context->request_id == 0)
525 wispr_portal_error(wp_context);
528 static bool wispr_input(const guint8 **data, gsize *length,
531 struct connman_wispr_portal_context *wp_context = user_data;
537 buf = g_string_sized_new(100);
539 g_string_append(buf, "button=Login&UserName=");
540 g_string_append_uri_escaped(buf, wp_context->wispr_username,
542 g_string_append(buf, "&Password=");
543 g_string_append_uri_escaped(buf, wp_context->wispr_password,
545 g_string_append(buf, "&FNAME=0&OriginatingServer=");
546 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
550 g_free(wp_context->wispr_formdata);
551 wp_context->wispr_formdata = g_string_free(buf, FALSE);
553 *data = (guint8 *) wp_context->wispr_formdata;
559 static void wispr_portal_browser_reply_cb(struct connman_service *service,
560 bool authentication_done,
561 const char *error, void *user_data)
563 struct connman_wispr_portal_context *wp_context = user_data;
564 struct connman_wispr_portal *wispr_portal;
569 if (!service || !wp_context)
573 * No way to cancel this if wp_context has been freed, so we lookup
574 * from the service and check that this is still the right context.
576 index = __connman_service_get_index(service);
580 wispr_portal = g_hash_table_lookup(wispr_portal_list,
581 GINT_TO_POINTER(index));
585 if (wp_context != wispr_portal->ipv4_context &&
586 wp_context != wispr_portal->ipv6_context)
589 if (!authentication_done) {
590 wispr_portal_error(wp_context);
591 free_wispr_routes(wp_context);
595 /* Restarting the test */
596 __connman_service_wispr_start(service, wp_context->type);
599 static void wispr_portal_request_wispr_login(struct connman_service *service,
601 const char *ssid, int ssid_len,
602 const char *username, const char *password,
603 bool wps, const char *wpspin,
604 const char *error, void *user_data)
606 struct connman_wispr_portal_context *wp_context = user_data;
612 "net.connman.Agent.Error.LaunchBrowser") == 0) {
613 if (__connman_agent_request_browser(service,
614 wispr_portal_browser_reply_cb,
615 wp_context->redirect_url,
616 wp_context) == -EINPROGRESS)
620 free_connman_wispr_portal_context(wp_context);
624 g_free(wp_context->wispr_username);
625 wp_context->wispr_username = g_strdup(username);
627 g_free(wp_context->wispr_password);
628 wp_context->wispr_password = g_strdup(password);
630 wp_context->request_id = g_web_request_post(wp_context->web,
631 wp_context->wispr_msg.login_url,
632 "application/x-www-form-urlencoded",
633 wispr_input, wispr_portal_web_result,
636 connman_wispr_message_init(&wp_context->wispr_msg);
639 static bool wispr_manage_message(GWebResult *result,
640 struct connman_wispr_portal_context *wp_context)
642 DBG("Message type: %s (%d)",
643 message_type_to_string(wp_context->wispr_msg.message_type),
644 wp_context->wispr_msg.message_type);
645 DBG("Response code: %s (%d)",
646 response_code_to_string(wp_context->wispr_msg.response_code),
647 wp_context->wispr_msg.response_code);
649 if (wp_context->wispr_msg.access_procedure)
650 DBG("Access procedure: %s",
651 wp_context->wispr_msg.access_procedure);
652 if (wp_context->wispr_msg.access_location)
653 DBG("Access location: %s",
654 wp_context->wispr_msg.access_location);
655 if (wp_context->wispr_msg.location_name)
656 DBG("Location name: %s",
657 wp_context->wispr_msg.location_name);
658 if (wp_context->wispr_msg.login_url)
659 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
660 if (wp_context->wispr_msg.abort_login_url)
661 DBG("Abort login URL: %s",
662 wp_context->wispr_msg.abort_login_url);
663 if (wp_context->wispr_msg.logoff_url)
664 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
666 switch (wp_context->wispr_msg.message_type) {
668 DBG("Login required");
670 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
672 if (__connman_agent_request_login_input(wp_context->service,
673 wispr_portal_request_wispr_login,
674 wp_context) != -EINPROGRESS)
675 wispr_portal_error(wp_context);
680 case 120: /* Falling down */
682 if (wp_context->wispr_msg.response_code == 50) {
683 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
685 g_free(wp_context->wispr_username);
686 wp_context->wispr_username = NULL;
688 g_free(wp_context->wispr_password);
689 wp_context->wispr_password = NULL;
691 g_free(wp_context->wispr_formdata);
692 wp_context->wispr_formdata = NULL;
694 wispr_portal_request_portal(wp_context);
698 wispr_portal_error(wp_context);
708 static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
710 struct connman_wispr_portal_context *wp_context = user_data;
711 const char *redirect = NULL;
712 const guint8 *chunk = NULL;
713 const char *str = NULL;
719 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
720 g_web_result_get_chunk(result, &chunk, &length);
723 g_web_parser_feed_data(wp_context->wispr_parser,
728 g_web_parser_end_data(wp_context->wispr_parser);
730 if (wp_context->wispr_msg.message_type >= 0) {
731 if (wispr_manage_message(result, wp_context))
736 status = g_web_result_get_status(result);
738 DBG("status: %03u", status);
742 __connman_agent_request_browser(wp_context->service,
743 wispr_portal_browser_reply_cb,
744 wp_context->status_url, wp_context);
747 if (wp_context->wispr_msg.message_type >= 0)
750 if (g_web_result_get_header(result, "X-ConnMan-Status",
752 portal_manage_status(result, wp_context);
755 __connman_agent_request_browser(wp_context->service,
756 wispr_portal_browser_reply_cb,
757 wp_context->redirect_url, wp_context);
766 if (!g_web_supports_tls() ||
767 !g_web_result_get_header(result, "Location",
770 __connman_agent_request_browser(wp_context->service,
771 wispr_portal_browser_reply_cb,
772 wp_context->status_url, wp_context);
776 DBG("Redirect URL: %s", redirect);
778 wp_context->redirect_url = g_strdup(redirect);
780 wp_context->request_id = g_web_request_get(wp_context->web,
781 redirect, wispr_portal_web_result,
782 wispr_route_request, wp_context);
787 __connman_service_online_check(wp_context->service,
788 wp_context->type, false);
792 __connman_agent_request_browser(wp_context->service,
793 wispr_portal_browser_reply_cb,
794 wp_context->status_url, wp_context);
800 free_wispr_routes(wp_context);
801 wp_context->request_id = 0;
803 wp_context->wispr_msg.message_type = -1;
807 static void proxy_callback(const char *proxy, void *user_data)
809 struct connman_wispr_portal_context *wp_context = user_data;
811 DBG("proxy %s", proxy);
816 wp_context->token = 0;
818 if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
819 if (g_str_has_prefix(proxy, "PROXY")) {
821 for (; *proxy == ' ' && *proxy != '\0'; proxy++);
823 g_web_set_proxy(wp_context->web, proxy);
826 g_web_set_accept(wp_context->web, NULL);
827 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
828 g_web_set_close_connection(wp_context->web, TRUE);
830 connman_wispr_message_init(&wp_context->wispr_msg);
832 wp_context->wispr_parser = g_web_parser_new(
833 "<WISPAccessGatewayParam",
834 "WISPAccessGatewayParam>",
835 xml_wispr_parser_callback, wp_context);
837 wispr_portal_request_portal(wp_context);
840 static gboolean no_proxy_callback(gpointer user_data)
842 struct connman_wispr_portal_context *wp_context = user_data;
844 wp_context->timeout = 0;
846 proxy_callback("DIRECT", wp_context);
851 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
853 enum connman_service_proxy_method proxy_method;
854 enum connman_service_type service_type;
855 char *interface = NULL;
856 char **nameservers = NULL;
861 DBG("wispr/portal context %p service %p", wp_context,
862 wp_context->service);
864 service_type = connman_service_get_type(wp_context->service);
866 switch (service_type) {
867 case CONNMAN_SERVICE_TYPE_ETHERNET:
868 case CONNMAN_SERVICE_TYPE_WIFI:
869 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
870 case CONNMAN_SERVICE_TYPE_CELLULAR:
871 case CONNMAN_SERVICE_TYPE_GADGET:
873 case CONNMAN_SERVICE_TYPE_UNKNOWN:
874 case CONNMAN_SERVICE_TYPE_SYSTEM:
875 case CONNMAN_SERVICE_TYPE_GPS:
876 case CONNMAN_SERVICE_TYPE_VPN:
877 case CONNMAN_SERVICE_TYPE_P2P:
881 interface = connman_service_get_interface(wp_context->service);
885 DBG("interface %s", interface);
887 if_index = connman_inet_ifindex(interface);
889 DBG("Could not get ifindex");
894 nameservers = connman_service_get_nameservers(wp_context->service);
896 DBG("Could not get nameservers");
901 wp_context->web = g_web_new(if_index);
902 if (!wp_context->web) {
903 DBG("Could not set up GWeb");
908 if (getenv("CONNMAN_WEB_DEBUG"))
909 g_web_set_debug(wp_context->web, web_debug, "WEB");
911 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
912 g_web_set_address_family(wp_context->web, AF_INET);
913 wp_context->status_url = STATUS_URL_IPV4;
915 g_web_set_address_family(wp_context->web, AF_INET6);
916 wp_context->status_url = STATUS_URL_IPV6;
919 for (i = 0; nameservers[i]; i++)
920 g_web_add_nameserver(wp_context->web, nameservers[i]);
922 proxy_method = connman_service_get_proxy_method(wp_context->service);
924 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
925 wp_context->token = connman_proxy_lookup(interface,
926 wp_context->status_url,
928 proxy_callback, wp_context);
930 if (wp_context->token == 0) {
932 free_connman_wispr_portal_context(wp_context);
934 } else if (wp_context->timeout == 0) {
935 wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
939 g_strfreev(nameservers);
945 int __connman_wispr_start(struct connman_service *service,
946 enum connman_ipconfig_type type)
948 struct connman_wispr_portal_context *wp_context = NULL;
949 struct connman_wispr_portal *wispr_portal = NULL;
952 DBG("service %p", service);
954 if (!wispr_portal_list)
957 index = __connman_service_get_index(service);
961 wispr_portal = g_hash_table_lookup(wispr_portal_list,
962 GINT_TO_POINTER(index));
964 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
968 g_hash_table_replace(wispr_portal_list,
969 GINT_TO_POINTER(index), wispr_portal);
972 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
973 wp_context = wispr_portal->ipv4_context;
974 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
975 wp_context = wispr_portal->ipv6_context;
979 /* If there is already an existing context, we wipe it */
981 free_connman_wispr_portal_context(wp_context);
983 wp_context = create_wispr_portal_context();
987 wp_context->service = service;
988 wp_context->type = type;
989 wp_context->wispr_portal = wispr_portal;
991 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
992 wispr_portal->ipv4_context = wp_context;
994 wispr_portal->ipv6_context = wp_context;
996 return wispr_portal_detect(wp_context);
999 void __connman_wispr_stop(struct connman_service *service)
1001 struct connman_wispr_portal *wispr_portal;
1004 DBG("service %p", service);
1006 if (!wispr_portal_list)
1009 index = __connman_service_get_index(service);
1013 wispr_portal = g_hash_table_lookup(wispr_portal_list,
1014 GINT_TO_POINTER(index));
1018 if (wispr_portal->ipv4_context) {
1019 if (service == wispr_portal->ipv4_context->service)
1020 g_hash_table_remove(wispr_portal_list,
1021 GINT_TO_POINTER(index));
1024 if (wispr_portal->ipv6_context) {
1025 if (service == wispr_portal->ipv6_context->service)
1026 g_hash_table_remove(wispr_portal_list,
1027 GINT_TO_POINTER(index));
1031 int __connman_wispr_init(void)
1035 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
1036 g_direct_equal, NULL,
1037 free_connman_wispr_portal);
1039 enable_online_to_ready_transition =
1040 connman_setting_get_bool("EnableOnlineToReadyTransition");
1045 void __connman_wispr_cleanup(void)
1049 g_hash_table_destroy(wispr_portal_list);
1050 wispr_portal_list = NULL;