5 * Copyright (C) 2007-2012 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 gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
97 static GHashTable *wispr_portal_list = NULL;
99 static void connman_wispr_message_init(struct connman_wispr_message *msg)
103 msg->has_error = FALSE;
104 msg->current_element = NULL;
106 msg->message_type = -1;
107 msg->response_code = -1;
109 g_free(msg->login_url);
110 msg->login_url = NULL;
112 g_free(msg->abort_login_url);
113 msg->abort_login_url = NULL;
115 g_free(msg->logoff_url);
116 msg->logoff_url = NULL;
118 g_free(msg->access_procedure);
119 msg->access_procedure = NULL;
121 g_free(msg->access_location);
122 msg->access_location = NULL;
124 g_free(msg->location_name);
125 msg->location_name = NULL;
128 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
130 while (wp_context->route_list != NULL) {
131 struct wispr_route *route = wp_context->route_list->data;
133 DBG("free route to %s if %d type %d", route->address,
134 route->if_index, wp_context->type);
136 switch(wp_context->type) {
137 case CONNMAN_IPCONFIG_TYPE_IPV4:
138 connman_inet_del_host_route(route->if_index,
141 case CONNMAN_IPCONFIG_TYPE_IPV6:
142 connman_inet_del_ipv6_host_route(route->if_index,
145 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
149 g_free(route->address);
152 wp_context->route_list =
153 g_slist_delete_link(wp_context->route_list,
154 wp_context->route_list);
158 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
160 DBG("context %p", wp_context);
162 if (wp_context == NULL)
165 if (wp_context->wispr_portal != NULL) {
166 if (wp_context->wispr_portal->ipv4_context == wp_context)
167 wp_context->wispr_portal->ipv4_context = NULL;
169 if (wp_context->wispr_portal->ipv6_context == wp_context)
170 wp_context->wispr_portal->ipv6_context = NULL;
173 if (wp_context->token > 0)
174 connman_proxy_lookup_cancel(wp_context->token);
176 if (wp_context->request_id > 0)
177 g_web_cancel_request(wp_context->web, wp_context->request_id);
179 if (wp_context->timeout > 0)
180 g_source_remove(wp_context->timeout);
182 if (wp_context->web != NULL)
183 g_web_unref(wp_context->web);
185 g_free(wp_context->redirect_url);
187 if (wp_context->wispr_parser != NULL)
188 g_web_parser_unref(wp_context->wispr_parser);
190 connman_wispr_message_init(&wp_context->wispr_msg);
192 g_free(wp_context->wispr_username);
193 g_free(wp_context->wispr_password);
194 g_free(wp_context->wispr_formdata);
196 free_wispr_routes(wp_context);
201 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
203 return g_try_new0(struct connman_wispr_portal_context, 1);
206 static void free_connman_wispr_portal(gpointer data)
208 struct connman_wispr_portal *wispr_portal = data;
212 if (wispr_portal == NULL)
215 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
216 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
218 g_free(wispr_portal);
221 static const char *message_type_to_string(int message_type)
223 switch (message_type) {
225 return "Initial redirect message";
227 return "Proxy notification";
229 return "Authentication notification";
231 return "Logoff notification";
233 return "Response to Authentication Poll";
235 return "Response to Abort Login";
241 static const char *response_code_to_string(int response_code)
243 switch (response_code) {
247 return "Login succeeded";
249 return "Login failed";
251 return "RADIUS server error/timeout";
253 return "RADIUS server not enabled";
255 return "Logoff succeeded";
257 return "Login aborted";
259 return "Proxy detection/repeat operation";
261 return "Authentication pending";
263 return "Access gateway internal error";
272 WISPR_ELEMENT_NONE = 0,
273 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
274 WISPR_ELEMENT_ACCESS_LOCATION = 2,
275 WISPR_ELEMENT_LOCATION_NAME = 3,
276 WISPR_ELEMENT_LOGIN_URL = 4,
277 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
278 WISPR_ELEMENT_MESSAGE_TYPE = 6,
279 WISPR_ELEMENT_RESPONSE_CODE = 7,
280 WISPR_ELEMENT_NEXT_URL = 8,
281 WISPR_ELEMENT_DELAY = 9,
282 WISPR_ELEMENT_REPLY_MESSAGE = 10,
283 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
284 WISPR_ELEMENT_LOGOFF_URL = 12,
286 } wispr_element_map[] = {
287 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
288 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
289 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
290 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
291 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
292 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
293 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
294 { "NextURL", WISPR_ELEMENT_NEXT_URL },
295 { "Delay", WISPR_ELEMENT_DELAY },
296 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
297 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
298 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
299 { NULL, WISPR_ELEMENT_NONE },
302 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
303 const gchar *element_name,
304 const gchar **attribute_names,
305 const gchar **attribute_values,
306 gpointer user_data, GError **error)
308 struct connman_wispr_message *msg = user_data;
310 msg->current_element = element_name;
313 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
314 const gchar *element_name,
315 gpointer user_data, GError **error)
317 struct connman_wispr_message *msg = user_data;
319 msg->current_element = NULL;
322 static void xml_wispr_text_handler(GMarkupParseContext *context,
323 const gchar *text, gsize text_len,
324 gpointer user_data, GError **error)
326 struct connman_wispr_message *msg = user_data;
329 if (msg->current_element == NULL)
332 for (i = 0; wispr_element_map[i].str; i++) {
333 if (g_str_equal(wispr_element_map[i].str,
334 msg->current_element) == FALSE)
337 switch (wispr_element_map[i].element) {
338 case WISPR_ELEMENT_NONE:
339 case WISPR_ELEMENT_ACCESS_PROCEDURE:
340 g_free(msg->access_procedure);
341 msg->access_procedure = g_strdup(text);
343 case WISPR_ELEMENT_ACCESS_LOCATION:
344 g_free(msg->access_location);
345 msg->access_location = g_strdup(text);
347 case WISPR_ELEMENT_LOCATION_NAME:
348 g_free(msg->location_name);
349 msg->location_name = g_strdup(text);
351 case WISPR_ELEMENT_LOGIN_URL:
352 g_free(msg->login_url);
353 msg->login_url = g_strdup(text);
355 case WISPR_ELEMENT_ABORT_LOGIN_URL:
356 g_free(msg->abort_login_url);
357 msg->abort_login_url = g_strdup(text);
359 case WISPR_ELEMENT_MESSAGE_TYPE:
360 msg->message_type = atoi(text);
362 case WISPR_ELEMENT_RESPONSE_CODE:
363 msg->response_code = atoi(text);
365 case WISPR_ELEMENT_NEXT_URL:
366 case WISPR_ELEMENT_DELAY:
367 case WISPR_ELEMENT_REPLY_MESSAGE:
368 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
370 case WISPR_ELEMENT_LOGOFF_URL:
371 g_free(msg->logoff_url);
372 msg->logoff_url = g_strdup(text);
378 static void xml_wispr_error_handler(GMarkupParseContext *context,
379 GError *error, gpointer user_data)
381 struct connman_wispr_message *msg = user_data;
383 msg->has_error = TRUE;
386 static const GMarkupParser xml_wispr_parser_handlers = {
387 xml_wispr_start_element_handler,
388 xml_wispr_end_element_handler,
389 xml_wispr_text_handler,
391 xml_wispr_error_handler,
394 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
396 struct connman_wispr_portal_context *wp_context = user_data;
397 GMarkupParseContext *parser_context = NULL;
402 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
403 G_MARKUP_TREAT_CDATA_AS_TEXT,
404 &(wp_context->wispr_msg), NULL);
406 result = g_markup_parse_context_parse(parser_context,
407 str, strlen(str), NULL);
409 g_markup_parse_context_end_parse(parser_context, NULL);
411 g_markup_parse_context_free(parser_context);
414 static void web_debug(const char *str, void *data)
416 connman_info("%s: %s\n", (const char *) data, str);
419 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
421 DBG("Failed to proceed wispr/portal web request");
423 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
426 static void portal_manage_status(GWebResult *result,
427 struct connman_wispr_portal_context *wp_context)
429 struct connman_service *service = wp_context->service;
430 enum connman_ipconfig_type type = wp_context->type;
431 const char *str = NULL;
435 /* We currently don't do anything with this info */
436 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
438 connman_info("Client-IP: %s", str);
440 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
442 connman_info("Client-Country: %s", str);
444 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
446 connman_info("Client-Region: %s", str);
448 free_connman_wispr_portal_context(wp_context);
450 __connman_service_ipconfig_indicate_state(service,
451 CONNMAN_SERVICE_STATE_ONLINE, type);
454 static gboolean wispr_route_request(const char *address, int ai_family,
455 int if_index, gpointer user_data)
458 struct connman_wispr_portal_context *wp_context = user_data;
460 struct wispr_route *route;
462 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
465 DBG("address %s if %d gw %s", address, if_index, gateway);
470 route = g_try_new0(struct wispr_route, 1);
472 DBG("could not create struct");
476 switch(wp_context->type) {
477 case CONNMAN_IPCONFIG_TYPE_IPV4:
478 result = connman_inet_add_host_route(if_index, address,
481 case CONNMAN_IPCONFIG_TYPE_IPV6:
482 result = connman_inet_add_ipv6_host_route(if_index, address,
485 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
494 route->address = g_strdup(address);
495 route->if_index = if_index;
496 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
501 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
505 wp_context->request_id = g_web_request_get(wp_context->web,
506 wp_context->status_url,
507 wispr_portal_web_result,
511 if (wp_context->request_id == 0)
512 wispr_portal_error(wp_context);
515 static gboolean wispr_input(const guint8 **data, gsize *length,
518 struct connman_wispr_portal_context *wp_context = user_data;
524 buf = g_string_sized_new(100);
526 g_string_append(buf, "button=Login&UserName=");
527 g_string_append_uri_escaped(buf, wp_context->wispr_username,
529 g_string_append(buf, "&Password=");
530 g_string_append_uri_escaped(buf, wp_context->wispr_password,
532 g_string_append(buf, "&FNAME=0&OriginatingServer=");
533 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
537 g_free(wp_context->wispr_formdata);
538 wp_context->wispr_formdata = g_string_free(buf, FALSE);
540 *data = (guint8 *) wp_context->wispr_formdata;
546 static void wispr_portal_browser_reply_cb(struct connman_service *service,
547 connman_bool_t authentication_done,
548 const char *error, void *user_data)
550 struct connman_wispr_portal_context *wp_context = user_data;
554 if (service == NULL || wp_context == NULL)
557 if (authentication_done == FALSE) {
558 wispr_portal_error(wp_context);
559 free_wispr_routes(wp_context);
563 /* Restarting the test */
564 __connman_wispr_start(service, wp_context->type);
567 static void wispr_portal_request_wispr_login(struct connman_service *service,
568 connman_bool_t success,
569 const char *ssid, int ssid_len,
570 const char *username, const char *password,
571 gboolean wps, const char *wpspin,
572 const char *error, void *user_data)
574 struct connman_wispr_portal_context *wp_context = user_data;
580 "net.connman.Agent.Error.LaunchBrowser") == 0) {
581 if (__connman_agent_request_browser(service,
582 wispr_portal_browser_reply_cb,
583 wp_context->redirect_url,
584 wp_context) == -EINPROGRESS)
588 free_connman_wispr_portal_context(wp_context);
592 g_free(wp_context->wispr_username);
593 wp_context->wispr_username = g_strdup(username);
595 g_free(wp_context->wispr_password);
596 wp_context->wispr_password = g_strdup(password);
598 wp_context->request_id = g_web_request_post(wp_context->web,
599 wp_context->wispr_msg.login_url,
600 "application/x-www-form-urlencoded",
601 wispr_input, wispr_portal_web_result,
604 connman_wispr_message_init(&wp_context->wispr_msg);
607 static gboolean wispr_manage_message(GWebResult *result,
608 struct connman_wispr_portal_context *wp_context)
610 DBG("Message type: %s (%d)",
611 message_type_to_string(wp_context->wispr_msg.message_type),
612 wp_context->wispr_msg.message_type);
613 DBG("Response code: %s (%d)",
614 response_code_to_string(wp_context->wispr_msg.response_code),
615 wp_context->wispr_msg.response_code);
617 if (wp_context->wispr_msg.access_procedure != NULL)
618 DBG("Access procedure: %s",
619 wp_context->wispr_msg.access_procedure);
620 if (wp_context->wispr_msg.access_location != NULL)
621 DBG("Access location: %s",
622 wp_context->wispr_msg.access_location);
623 if (wp_context->wispr_msg.location_name != NULL)
624 DBG("Location name: %s",
625 wp_context->wispr_msg.location_name);
626 if (wp_context->wispr_msg.login_url != NULL)
627 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
628 if (wp_context->wispr_msg.abort_login_url != NULL)
629 DBG("Abort login URL: %s",
630 wp_context->wispr_msg.abort_login_url);
631 if (wp_context->wispr_msg.logoff_url != NULL)
632 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
634 switch (wp_context->wispr_msg.message_type) {
636 DBG("Login required");
638 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
640 if (__connman_agent_request_login_input(wp_context->service,
641 wispr_portal_request_wispr_login,
642 wp_context) != -EINPROGRESS)
643 wispr_portal_error(wp_context);
646 case 120: /* Falling down */
648 if (wp_context->wispr_msg.response_code == 50) {
649 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
651 g_free(wp_context->wispr_username);
652 wp_context->wispr_username = NULL;
654 g_free(wp_context->wispr_password);
655 wp_context->wispr_password = NULL;
657 g_free(wp_context->wispr_formdata);
658 wp_context->wispr_formdata = NULL;
660 wispr_portal_request_portal(wp_context);
664 wispr_portal_error(wp_context);
674 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
676 struct connman_wispr_portal_context *wp_context = user_data;
677 const char *redirect = NULL;
678 const guint8 *chunk = NULL;
679 const char *str = NULL;
685 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
686 g_web_result_get_chunk(result, &chunk, &length);
689 g_web_parser_feed_data(wp_context->wispr_parser,
694 g_web_parser_end_data(wp_context->wispr_parser);
696 if (wp_context->wispr_msg.message_type >= 0) {
697 if (wispr_manage_message(result, wp_context) == TRUE)
702 status = g_web_result_get_status(result);
704 DBG("status: %03u", status);
708 if (wp_context->wispr_msg.message_type >= 0)
711 if (g_web_result_get_header(result, "X-ConnMan-Status",
713 portal_manage_status(result, wp_context);
717 __connman_agent_request_browser(wp_context->service,
718 wispr_portal_browser_reply_cb,
719 wp_context->redirect_url, wp_context);
723 if (g_web_supports_tls() == FALSE ||
724 g_web_result_get_header(result, "Location",
725 &redirect) == FALSE) {
727 __connman_agent_request_browser(wp_context->service,
728 wispr_portal_browser_reply_cb,
729 wp_context->status_url, wp_context);
733 DBG("Redirect URL: %s", redirect);
735 wp_context->redirect_url = g_strdup(redirect);
737 wp_context->request_id = g_web_request_get(wp_context->web,
738 redirect, wispr_portal_web_result,
739 wispr_route_request, wp_context);
744 if (__connman_service_online_check_failed(wp_context->service,
745 wp_context->type) == 0) {
746 wispr_portal_error(wp_context);
747 free_connman_wispr_portal_context(wp_context);
756 free_wispr_routes(wp_context);
757 wp_context->request_id = 0;
759 wp_context->wispr_msg.message_type = -1;
763 static void proxy_callback(const char *proxy, void *user_data)
765 struct connman_wispr_portal_context *wp_context = user_data;
767 DBG("proxy %s", proxy);
769 if (wp_context == NULL)
772 wp_context->token = 0;
774 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
775 g_web_set_proxy(wp_context->web, proxy);
777 g_web_set_accept(wp_context->web, NULL);
778 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
779 g_web_set_close_connection(wp_context->web, TRUE);
781 connman_wispr_message_init(&wp_context->wispr_msg);
783 wp_context->wispr_parser = g_web_parser_new(
784 "<WISPAccessGatewayParam",
785 "WISPAccessGatewayParam>",
786 xml_wispr_parser_callback, wp_context);
788 wispr_portal_request_portal(wp_context);
791 static gboolean no_proxy_callback(gpointer user_data)
793 struct connman_wispr_portal_context *wp_context = user_data;
795 wp_context->timeout = 0;
797 proxy_callback("DIRECT", wp_context);
802 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
804 enum connman_service_proxy_method proxy_method;
805 enum connman_service_type service_type;
806 char *interface = NULL;
807 char **nameservers = NULL;
812 DBG("wispr/portal context %p", wp_context);
813 DBG("service %p", wp_context->service);
815 service_type = connman_service_get_type(wp_context->service);
817 switch (service_type) {
818 case CONNMAN_SERVICE_TYPE_ETHERNET:
819 case CONNMAN_SERVICE_TYPE_WIFI:
820 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
821 case CONNMAN_SERVICE_TYPE_CELLULAR:
823 case CONNMAN_SERVICE_TYPE_UNKNOWN:
824 case CONNMAN_SERVICE_TYPE_SYSTEM:
825 case CONNMAN_SERVICE_TYPE_GPS:
826 case CONNMAN_SERVICE_TYPE_VPN:
827 case CONNMAN_SERVICE_TYPE_GADGET:
831 interface = connman_service_get_interface(wp_context->service);
832 if (interface == NULL)
835 DBG("interface %s", interface);
837 if_index = connman_inet_ifindex(interface);
839 DBG("Could not get ifindex");
844 nameservers = connman_service_get_nameservers(wp_context->service);
845 if (nameservers == NULL) {
846 DBG("Could not get nameservers");
851 wp_context->web = g_web_new(if_index);
852 if (wp_context->web == NULL) {
853 DBG("Could not set up GWeb");
858 if (getenv("CONNMAN_WEB_DEBUG"))
859 g_web_set_debug(wp_context->web, web_debug, "WEB");
861 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
862 g_web_set_address_family(wp_context->web, AF_INET);
863 wp_context->status_url = STATUS_URL_IPV4;
865 g_web_set_address_family(wp_context->web, AF_INET6);
866 wp_context->status_url = STATUS_URL_IPV6;
869 for (i = 0; nameservers[i] != NULL; i++)
870 g_web_add_nameserver(wp_context->web, nameservers[i]);
872 proxy_method = connman_service_get_proxy_method(wp_context->service);
874 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
875 wp_context->token = connman_proxy_lookup(interface,
876 wp_context->status_url,
878 proxy_callback, wp_context);
880 if (wp_context->token == 0) {
882 free_connman_wispr_portal_context(wp_context);
884 } else if (wp_context->timeout == 0) {
885 wp_context->timeout =
886 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
890 g_strfreev(nameservers);
896 int __connman_wispr_start(struct connman_service *service,
897 enum connman_ipconfig_type type)
899 struct connman_wispr_portal_context *wp_context = NULL;
900 struct connman_wispr_portal *wispr_portal = NULL;
903 DBG("service %p", service);
905 if (wispr_portal_list == NULL)
908 index = __connman_service_get_index(service);
912 wispr_portal = g_hash_table_lookup(wispr_portal_list,
913 GINT_TO_POINTER(index));
914 if (wispr_portal == NULL) {
915 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
916 if (wispr_portal == NULL)
919 g_hash_table_replace(wispr_portal_list,
920 GINT_TO_POINTER(index), wispr_portal);
923 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
924 wp_context = wispr_portal->ipv4_context;
925 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
926 wp_context = wispr_portal->ipv6_context;
930 /* If there is already an existing context, we wipe it */
931 if (wp_context != NULL)
932 free_connman_wispr_portal_context(wp_context);
934 wp_context = create_wispr_portal_context();
935 if (wp_context == NULL)
938 wp_context->service = service;
939 wp_context->type = type;
940 wp_context->wispr_portal = wispr_portal;
942 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
943 wispr_portal->ipv4_context = wp_context;
945 wispr_portal->ipv6_context = wp_context;
947 return wispr_portal_detect(wp_context);
950 void __connman_wispr_stop(struct connman_service *service)
954 DBG("service %p", service);
956 if (wispr_portal_list == NULL)
959 index = __connman_service_get_index(service);
963 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
966 int __connman_wispr_init(void)
970 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
971 g_direct_equal, NULL,
972 free_connman_wispr_portal);
977 void __connman_wispr_cleanup(void)
981 g_hash_table_destroy(wispr_portal_list);
982 wispr_portal_list = NULL;