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 if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
450 connman_info("Client-Timezone: %s", str);
452 free_connman_wispr_portal_context(wp_context);
454 __connman_service_ipconfig_indicate_state(service,
455 CONNMAN_SERVICE_STATE_ONLINE, type);
458 static gboolean wispr_route_request(const char *address, int ai_family,
459 int if_index, gpointer user_data)
462 struct connman_wispr_portal_context *wp_context = user_data;
464 struct wispr_route *route;
466 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
469 DBG("address %s if %d gw %s", address, if_index, gateway);
474 route = g_try_new0(struct wispr_route, 1);
476 DBG("could not create struct");
480 switch(wp_context->type) {
481 case CONNMAN_IPCONFIG_TYPE_IPV4:
482 result = connman_inet_add_host_route(if_index, address,
485 case CONNMAN_IPCONFIG_TYPE_IPV6:
486 result = connman_inet_add_ipv6_host_route(if_index, address,
489 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
498 route->address = g_strdup(address);
499 route->if_index = if_index;
500 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
505 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
509 wp_context->request_id = g_web_request_get(wp_context->web,
510 wp_context->status_url,
511 wispr_portal_web_result,
515 if (wp_context->request_id == 0)
516 wispr_portal_error(wp_context);
519 static gboolean wispr_input(const guint8 **data, gsize *length,
522 struct connman_wispr_portal_context *wp_context = user_data;
528 buf = g_string_sized_new(100);
530 g_string_append(buf, "button=Login&UserName=");
531 g_string_append_uri_escaped(buf, wp_context->wispr_username,
533 g_string_append(buf, "&Password=");
534 g_string_append_uri_escaped(buf, wp_context->wispr_password,
536 g_string_append(buf, "&FNAME=0&OriginatingServer=");
537 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
541 g_free(wp_context->wispr_formdata);
542 wp_context->wispr_formdata = g_string_free(buf, FALSE);
544 *data = (guint8 *) wp_context->wispr_formdata;
550 static void wispr_portal_browser_reply_cb(struct connman_service *service,
551 connman_bool_t authentication_done,
552 const char *error, void *user_data)
554 struct connman_wispr_portal_context *wp_context = user_data;
558 if (service == NULL || wp_context == NULL)
561 if (authentication_done == FALSE) {
562 wispr_portal_error(wp_context);
563 free_wispr_routes(wp_context);
567 /* Restarting the test */
568 __connman_wispr_start(service, wp_context->type);
571 static void wispr_portal_request_wispr_login(struct connman_service *service,
572 connman_bool_t success,
573 const char *ssid, int ssid_len,
574 const char *username, const char *password,
575 gboolean wps, const char *wpspin,
576 const char *error, void *user_data)
578 struct connman_wispr_portal_context *wp_context = user_data;
584 "net.connman.Agent.Error.LaunchBrowser") == 0) {
585 if (__connman_agent_request_browser(service,
586 wispr_portal_browser_reply_cb,
587 wp_context->redirect_url,
588 wp_context) == -EINPROGRESS)
592 free_connman_wispr_portal_context(wp_context);
596 g_free(wp_context->wispr_username);
597 wp_context->wispr_username = g_strdup(username);
599 g_free(wp_context->wispr_password);
600 wp_context->wispr_password = g_strdup(password);
602 wp_context->request_id = g_web_request_post(wp_context->web,
603 wp_context->wispr_msg.login_url,
604 "application/x-www-form-urlencoded",
605 wispr_input, wispr_portal_web_result,
608 connman_wispr_message_init(&wp_context->wispr_msg);
611 static gboolean wispr_manage_message(GWebResult *result,
612 struct connman_wispr_portal_context *wp_context)
614 DBG("Message type: %s (%d)",
615 message_type_to_string(wp_context->wispr_msg.message_type),
616 wp_context->wispr_msg.message_type);
617 DBG("Response code: %s (%d)",
618 response_code_to_string(wp_context->wispr_msg.response_code),
619 wp_context->wispr_msg.response_code);
621 if (wp_context->wispr_msg.access_procedure != NULL)
622 DBG("Access procedure: %s",
623 wp_context->wispr_msg.access_procedure);
624 if (wp_context->wispr_msg.access_location != NULL)
625 DBG("Access location: %s",
626 wp_context->wispr_msg.access_location);
627 if (wp_context->wispr_msg.location_name != NULL)
628 DBG("Location name: %s",
629 wp_context->wispr_msg.location_name);
630 if (wp_context->wispr_msg.login_url != NULL)
631 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
632 if (wp_context->wispr_msg.abort_login_url != NULL)
633 DBG("Abort login URL: %s",
634 wp_context->wispr_msg.abort_login_url);
635 if (wp_context->wispr_msg.logoff_url != NULL)
636 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
638 switch (wp_context->wispr_msg.message_type) {
640 DBG("Login required");
642 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
644 if (__connman_agent_request_login_input(wp_context->service,
645 wispr_portal_request_wispr_login,
646 wp_context) != -EINPROGRESS)
647 wispr_portal_error(wp_context);
650 case 120: /* Falling down */
652 if (wp_context->wispr_msg.response_code == 50) {
653 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
655 g_free(wp_context->wispr_username);
656 wp_context->wispr_username = NULL;
658 g_free(wp_context->wispr_password);
659 wp_context->wispr_password = NULL;
661 g_free(wp_context->wispr_formdata);
662 wp_context->wispr_formdata = NULL;
664 wispr_portal_request_portal(wp_context);
668 wispr_portal_error(wp_context);
678 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
680 struct connman_wispr_portal_context *wp_context = user_data;
681 const char *redirect = NULL;
682 const guint8 *chunk = NULL;
683 const char *str = NULL;
689 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
690 g_web_result_get_chunk(result, &chunk, &length);
693 g_web_parser_feed_data(wp_context->wispr_parser,
698 g_web_parser_end_data(wp_context->wispr_parser);
700 if (wp_context->wispr_msg.message_type >= 0) {
701 if (wispr_manage_message(result, wp_context) == TRUE)
706 status = g_web_result_get_status(result);
708 DBG("status: %03u", status);
712 if (wp_context->wispr_msg.message_type >= 0)
715 if (g_web_result_get_header(result, "X-ConnMan-Status",
717 portal_manage_status(result, wp_context);
721 __connman_agent_request_browser(wp_context->service,
722 wispr_portal_browser_reply_cb,
723 wp_context->redirect_url, wp_context);
727 if (g_web_supports_tls() == FALSE ||
728 g_web_result_get_header(result, "Location",
729 &redirect) == FALSE) {
731 __connman_agent_request_browser(wp_context->service,
732 wispr_portal_browser_reply_cb,
733 wp_context->status_url, wp_context);
737 DBG("Redirect URL: %s", redirect);
739 wp_context->redirect_url = g_strdup(redirect);
741 wp_context->request_id = g_web_request_get(wp_context->web,
742 redirect, wispr_portal_web_result,
743 wispr_route_request, wp_context);
748 if (__connman_service_online_check_failed(wp_context->service,
749 wp_context->type) == 0) {
750 wispr_portal_error(wp_context);
751 free_connman_wispr_portal_context(wp_context);
760 free_wispr_routes(wp_context);
761 wp_context->request_id = 0;
763 wp_context->wispr_msg.message_type = -1;
767 static void proxy_callback(const char *proxy, void *user_data)
769 struct connman_wispr_portal_context *wp_context = user_data;
771 DBG("proxy %s", proxy);
773 if (wp_context == NULL)
776 wp_context->token = 0;
778 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
779 g_web_set_proxy(wp_context->web, proxy);
781 g_web_set_accept(wp_context->web, NULL);
782 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
783 g_web_set_close_connection(wp_context->web, TRUE);
785 connman_wispr_message_init(&wp_context->wispr_msg);
787 wp_context->wispr_parser = g_web_parser_new(
788 "<WISPAccessGatewayParam",
789 "WISPAccessGatewayParam>",
790 xml_wispr_parser_callback, wp_context);
792 wispr_portal_request_portal(wp_context);
795 static gboolean no_proxy_callback(gpointer user_data)
797 struct connman_wispr_portal_context *wp_context = user_data;
799 wp_context->timeout = 0;
801 proxy_callback("DIRECT", wp_context);
806 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
808 enum connman_service_proxy_method proxy_method;
809 enum connman_service_type service_type;
810 char *interface = NULL;
811 char **nameservers = NULL;
816 DBG("wispr/portal context %p", wp_context);
817 DBG("service %p", wp_context->service);
819 service_type = connman_service_get_type(wp_context->service);
821 switch (service_type) {
822 case CONNMAN_SERVICE_TYPE_ETHERNET:
823 case CONNMAN_SERVICE_TYPE_WIFI:
824 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
825 case CONNMAN_SERVICE_TYPE_CELLULAR:
827 case CONNMAN_SERVICE_TYPE_UNKNOWN:
828 case CONNMAN_SERVICE_TYPE_SYSTEM:
829 case CONNMAN_SERVICE_TYPE_GPS:
830 case CONNMAN_SERVICE_TYPE_VPN:
831 case CONNMAN_SERVICE_TYPE_GADGET:
835 interface = connman_service_get_interface(wp_context->service);
836 if (interface == NULL)
839 DBG("interface %s", interface);
841 if_index = connman_inet_ifindex(interface);
843 DBG("Could not get ifindex");
848 nameservers = connman_service_get_nameservers(wp_context->service);
849 if (nameservers == NULL) {
850 DBG("Could not get nameservers");
855 wp_context->web = g_web_new(if_index);
856 if (wp_context->web == NULL) {
857 DBG("Could not set up GWeb");
862 if (getenv("CONNMAN_WEB_DEBUG"))
863 g_web_set_debug(wp_context->web, web_debug, "WEB");
865 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
866 g_web_set_address_family(wp_context->web, AF_INET);
867 wp_context->status_url = STATUS_URL_IPV4;
869 g_web_set_address_family(wp_context->web, AF_INET6);
870 wp_context->status_url = STATUS_URL_IPV6;
873 for (i = 0; nameservers[i] != NULL; i++)
874 g_web_add_nameserver(wp_context->web, nameservers[i]);
876 proxy_method = connman_service_get_proxy_method(wp_context->service);
878 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
879 wp_context->token = connman_proxy_lookup(interface,
880 wp_context->status_url,
882 proxy_callback, wp_context);
884 if (wp_context->token == 0) {
886 free_connman_wispr_portal_context(wp_context);
888 } else if (wp_context->timeout == 0) {
889 wp_context->timeout =
890 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
894 g_strfreev(nameservers);
900 int __connman_wispr_start(struct connman_service *service,
901 enum connman_ipconfig_type type)
903 struct connman_wispr_portal_context *wp_context = NULL;
904 struct connman_wispr_portal *wispr_portal = NULL;
907 DBG("service %p", service);
909 if (wispr_portal_list == NULL)
912 index = __connman_service_get_index(service);
916 wispr_portal = g_hash_table_lookup(wispr_portal_list,
917 GINT_TO_POINTER(index));
918 if (wispr_portal == NULL) {
919 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
920 if (wispr_portal == NULL)
923 g_hash_table_replace(wispr_portal_list,
924 GINT_TO_POINTER(index), wispr_portal);
927 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
928 wp_context = wispr_portal->ipv4_context;
929 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
930 wp_context = wispr_portal->ipv6_context;
934 /* If there is already an existing context, we wipe it */
935 if (wp_context != NULL)
936 free_connman_wispr_portal_context(wp_context);
938 wp_context = create_wispr_portal_context();
939 if (wp_context == NULL)
942 wp_context->service = service;
943 wp_context->type = type;
944 wp_context->wispr_portal = wispr_portal;
946 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
947 wispr_portal->ipv4_context = wp_context;
949 wispr_portal->ipv6_context = wp_context;
951 return wispr_portal_detect(wp_context);
954 void __connman_wispr_stop(struct connman_service *service)
958 DBG("service %p", service);
960 if (wispr_portal_list == NULL)
963 index = __connman_service_get_index(service);
967 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
970 int __connman_wispr_init(void)
974 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
975 g_direct_equal, NULL,
976 free_connman_wispr_portal);
981 void __connman_wispr_cleanup(void)
985 g_hash_table_destroy(wispr_portal_list);
986 wispr_portal_list = NULL;