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;
88 struct connman_wispr_portal {
89 struct connman_wispr_portal_context *ipv4_context;
90 struct connman_wispr_portal_context *ipv6_context;
93 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data);
95 static GHashTable *wispr_portal_list = NULL;
97 static void connman_wispr_message_init(struct connman_wispr_message *msg)
101 msg->has_error = FALSE;
102 msg->current_element = NULL;
104 msg->message_type = -1;
105 msg->response_code = -1;
107 g_free(msg->login_url);
108 msg->login_url = NULL;
110 g_free(msg->abort_login_url);
111 msg->abort_login_url = NULL;
113 g_free(msg->logoff_url);
114 msg->logoff_url = NULL;
116 g_free(msg->access_procedure);
117 msg->access_procedure = NULL;
119 g_free(msg->access_location);
120 msg->access_location = NULL;
122 g_free(msg->location_name);
123 msg->location_name = NULL;
126 static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
128 while (wp_context->route_list != NULL) {
129 struct wispr_route *route = wp_context->route_list->data;
131 DBG("free route to %s if %d type %d", route->address,
132 route->if_index, wp_context->type);
134 switch(wp_context->type) {
135 case CONNMAN_IPCONFIG_TYPE_IPV4:
136 connman_inet_del_host_route(route->if_index,
139 case CONNMAN_IPCONFIG_TYPE_IPV6:
140 connman_inet_del_ipv6_host_route(route->if_index,
143 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
147 g_free(route->address);
150 wp_context->route_list =
151 g_slist_delete_link(wp_context->route_list,
152 wp_context->route_list);
156 static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
158 DBG("context %p", wp_context);
160 if (wp_context == NULL)
163 if (wp_context->wispr_portal != NULL) {
164 if (wp_context->wispr_portal->ipv4_context == wp_context)
165 wp_context->wispr_portal->ipv4_context = NULL;
167 if (wp_context->wispr_portal->ipv6_context == wp_context)
168 wp_context->wispr_portal->ipv6_context = NULL;
171 if (wp_context->service != NULL)
172 connman_service_unref(wp_context->service);
174 if (wp_context->token > 0)
175 connman_proxy_lookup_cancel(wp_context->token);
177 if (wp_context->request_id > 0)
178 g_web_cancel_request(wp_context->web, wp_context->request_id);
180 if (wp_context->web != NULL)
181 g_web_unref(wp_context->web);
183 g_free(wp_context->redirect_url);
185 if (wp_context->wispr_parser != NULL)
186 g_web_parser_unref(wp_context->wispr_parser);
188 connman_wispr_message_init(&wp_context->wispr_msg);
190 g_free(wp_context->wispr_username);
191 g_free(wp_context->wispr_password);
192 g_free(wp_context->wispr_formdata);
194 free_wispr_routes(wp_context);
199 static struct connman_wispr_portal_context *create_wispr_portal_context(void)
201 return g_try_new0(struct connman_wispr_portal_context, 1);
204 static void free_connman_wispr_portal(gpointer data)
206 struct connman_wispr_portal *wispr_portal = data;
210 if (wispr_portal == NULL)
213 free_connman_wispr_portal_context(wispr_portal->ipv4_context);
214 free_connman_wispr_portal_context(wispr_portal->ipv6_context);
216 g_free(wispr_portal);
219 static const char *message_type_to_string(int message_type)
221 switch (message_type) {
223 return "Initial redirect message";
225 return "Proxy notification";
227 return "Authentication notification";
229 return "Logoff notification";
231 return "Response to Authentication Poll";
233 return "Response to Abort Login";
239 static const char *response_code_to_string(int response_code)
241 switch (response_code) {
245 return "Login succeeded";
247 return "Login failed";
249 return "RADIUS server error/timeout";
251 return "RADIUS server not enabled";
253 return "Logoff succeeded";
255 return "Login aborted";
257 return "Proxy detection/repeat operation";
259 return "Authentication pending";
261 return "Access gateway internal error";
270 WISPR_ELEMENT_NONE = 0,
271 WISPR_ELEMENT_ACCESS_PROCEDURE = 1,
272 WISPR_ELEMENT_ACCESS_LOCATION = 2,
273 WISPR_ELEMENT_LOCATION_NAME = 3,
274 WISPR_ELEMENT_LOGIN_URL = 4,
275 WISPR_ELEMENT_ABORT_LOGIN_URL = 5,
276 WISPR_ELEMENT_MESSAGE_TYPE = 6,
277 WISPR_ELEMENT_RESPONSE_CODE = 7,
278 WISPR_ELEMENT_NEXT_URL = 8,
279 WISPR_ELEMENT_DELAY = 9,
280 WISPR_ELEMENT_REPLY_MESSAGE = 10,
281 WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
282 WISPR_ELEMENT_LOGOFF_URL = 12,
284 } wispr_element_map[] = {
285 { "AccessProcedure", WISPR_ELEMENT_ACCESS_PROCEDURE },
286 { "AccessLocation", WISPR_ELEMENT_ACCESS_LOCATION },
287 { "LocationName", WISPR_ELEMENT_LOCATION_NAME },
288 { "LoginURL", WISPR_ELEMENT_LOGIN_URL },
289 { "AbortLoginURL", WISPR_ELEMENT_ABORT_LOGIN_URL },
290 { "MessageType", WISPR_ELEMENT_MESSAGE_TYPE },
291 { "ResponseCode", WISPR_ELEMENT_RESPONSE_CODE },
292 { "NextURL", WISPR_ELEMENT_NEXT_URL },
293 { "Delay", WISPR_ELEMENT_DELAY },
294 { "ReplyMessage", WISPR_ELEMENT_REPLY_MESSAGE },
295 { "LoginResultsURL", WISPR_ELEMENT_LOGIN_RESULTS_URL },
296 { "LogoffURL", WISPR_ELEMENT_LOGOFF_URL },
297 { NULL, WISPR_ELEMENT_NONE },
300 static void xml_wispr_start_element_handler(GMarkupParseContext *context,
301 const gchar *element_name,
302 const gchar **attribute_names,
303 const gchar **attribute_values,
304 gpointer user_data, GError **error)
306 struct connman_wispr_message *msg = user_data;
308 msg->current_element = element_name;
311 static void xml_wispr_end_element_handler(GMarkupParseContext *context,
312 const gchar *element_name,
313 gpointer user_data, GError **error)
315 struct connman_wispr_message *msg = user_data;
317 msg->current_element = NULL;
320 static void xml_wispr_text_handler(GMarkupParseContext *context,
321 const gchar *text, gsize text_len,
322 gpointer user_data, GError **error)
324 struct connman_wispr_message *msg = user_data;
327 if (msg->current_element == NULL)
330 for (i = 0; wispr_element_map[i].str; i++) {
331 if (g_str_equal(wispr_element_map[i].str,
332 msg->current_element) == FALSE)
335 switch (wispr_element_map[i].element) {
336 case WISPR_ELEMENT_NONE:
337 case WISPR_ELEMENT_ACCESS_PROCEDURE:
338 g_free(msg->access_procedure);
339 msg->access_procedure = g_strdup(text);
341 case WISPR_ELEMENT_ACCESS_LOCATION:
342 g_free(msg->access_location);
343 msg->access_location = g_strdup(text);
345 case WISPR_ELEMENT_LOCATION_NAME:
346 g_free(msg->location_name);
347 msg->location_name = g_strdup(text);
349 case WISPR_ELEMENT_LOGIN_URL:
350 g_free(msg->login_url);
351 msg->login_url = g_strdup(text);
353 case WISPR_ELEMENT_ABORT_LOGIN_URL:
354 g_free(msg->abort_login_url);
355 msg->abort_login_url = g_strdup(text);
357 case WISPR_ELEMENT_MESSAGE_TYPE:
358 msg->message_type = atoi(text);
360 case WISPR_ELEMENT_RESPONSE_CODE:
361 msg->response_code = atoi(text);
363 case WISPR_ELEMENT_NEXT_URL:
364 case WISPR_ELEMENT_DELAY:
365 case WISPR_ELEMENT_REPLY_MESSAGE:
366 case WISPR_ELEMENT_LOGIN_RESULTS_URL:
368 case WISPR_ELEMENT_LOGOFF_URL:
369 g_free(msg->logoff_url);
370 msg->logoff_url = g_strdup(text);
376 static void xml_wispr_error_handler(GMarkupParseContext *context,
377 GError *error, gpointer user_data)
379 struct connman_wispr_message *msg = user_data;
381 msg->has_error = TRUE;
384 static const GMarkupParser xml_wispr_parser_handlers = {
385 xml_wispr_start_element_handler,
386 xml_wispr_end_element_handler,
387 xml_wispr_text_handler,
389 xml_wispr_error_handler,
392 static void xml_wispr_parser_callback(const char *str, gpointer user_data)
394 struct connman_wispr_portal_context *wp_context = user_data;
395 GMarkupParseContext *parser_context = NULL;
400 parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
401 G_MARKUP_TREAT_CDATA_AS_TEXT,
402 &(wp_context->wispr_msg), NULL);
404 result = g_markup_parse_context_parse(parser_context,
405 str, strlen(str), NULL);
407 g_markup_parse_context_end_parse(parser_context, NULL);
409 g_markup_parse_context_free(parser_context);
412 static void web_debug(const char *str, void *data)
414 connman_info("%s: %s\n", (const char *) data, str);
417 static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
419 DBG("Failed to proceed wispr/portal web request");
421 wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
424 static void portal_manage_status(GWebResult *result,
425 struct connman_wispr_portal_context *wp_context)
427 const char *str = NULL;
431 /* We currently don't do anything with this info */
432 if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
434 connman_info("Client-IP: %s", str);
436 if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
438 connman_info("Client-Country: %s", str);
440 if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
442 connman_info("Client-Region: %s", str);
444 __connman_service_ipconfig_indicate_state(wp_context->service,
445 CONNMAN_SERVICE_STATE_ONLINE,
449 static gboolean wispr_route_request(const char *address, int ai_family,
450 int if_index, gpointer user_data)
453 struct connman_wispr_portal_context *wp_context = user_data;
455 struct wispr_route *route;
457 gateway = __connman_ipconfig_get_gateway_from_index(if_index,
460 DBG("address %s if %d gw %s", address, if_index, gateway);
465 route = g_try_new0(struct wispr_route, 1);
467 DBG("could not create struct");
471 switch(wp_context->type) {
472 case CONNMAN_IPCONFIG_TYPE_IPV4:
473 result = connman_inet_add_host_route(if_index, address,
476 case CONNMAN_IPCONFIG_TYPE_IPV6:
477 result = connman_inet_add_ipv6_host_route(if_index, address,
480 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
489 route->address = g_strdup(address);
490 route->if_index = if_index;
491 wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
496 static void wispr_portal_request_portal(struct connman_wispr_portal_context *wp_context)
500 wp_context->request_id = g_web_request_get(wp_context->web,
501 wp_context->status_url,
502 wispr_portal_web_result,
506 if (wp_context->request_id == 0)
507 wispr_portal_error(wp_context);
510 static gboolean wispr_input(const guint8 **data, gsize *length,
513 struct connman_wispr_portal_context *wp_context = user_data;
519 buf = g_string_sized_new(100);
521 g_string_append(buf, "button=Login&UserName=");
522 g_string_append_uri_escaped(buf, wp_context->wispr_username,
524 g_string_append(buf, "&Password=");
525 g_string_append_uri_escaped(buf, wp_context->wispr_password,
527 g_string_append(buf, "&FNAME=0&OriginatingServer=");
528 g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
532 g_free(wp_context->wispr_formdata);
533 wp_context->wispr_formdata = g_string_free(buf, FALSE);
535 *data = (guint8 *) wp_context->wispr_formdata;
541 static void wispr_portal_browser_reply_cb(struct connman_service *service,
542 connman_bool_t authentication_done,
543 const char *error, void *user_data)
545 struct connman_wispr_portal_context *wp_context = user_data;
549 if (service == NULL || wp_context == NULL)
552 if (authentication_done == FALSE) {
553 wispr_portal_error(wp_context);
554 free_wispr_routes(wp_context);
558 /* Restarting the test */
559 __connman_wispr_start(service, wp_context->type);
562 static void wispr_portal_request_wispr_login(struct connman_service *service,
563 connman_bool_t success,
564 const char *ssid, int ssid_len,
565 const char *username, const char *password,
566 gboolean wps, const char *wpspin,
567 const char *error, void *user_data)
569 struct connman_wispr_portal_context *wp_context = user_data;
573 if (error != NULL && g_strcmp0(error,
574 "net.connman.Agent.Error.LaunchBrowser") == 0) {
576 if (__connman_agent_request_browser(service,
577 wispr_portal_browser_reply_cb,
578 wp_context->redirect_url,
579 wp_context) != -EINPROGRESS)
580 free_connman_wispr_portal_context(wp_context);
585 g_free(wp_context->wispr_username);
586 wp_context->wispr_username = g_strdup(username);
588 g_free(wp_context->wispr_password);
589 wp_context->wispr_password = g_strdup(password);
591 wp_context->request_id = g_web_request_post(wp_context->web,
592 wp_context->wispr_msg.login_url,
593 "application/x-www-form-urlencoded",
594 wispr_input, wispr_portal_web_result,
597 connman_wispr_message_init(&wp_context->wispr_msg);
600 static gboolean wispr_manage_message(GWebResult *result,
601 struct connman_wispr_portal_context *wp_context)
603 DBG("Message type: %s (%d)",
604 message_type_to_string(wp_context->wispr_msg.message_type),
605 wp_context->wispr_msg.message_type);
606 DBG("Response code: %s (%d)",
607 response_code_to_string(wp_context->wispr_msg.response_code),
608 wp_context->wispr_msg.response_code);
610 if (wp_context->wispr_msg.access_procedure != NULL)
611 DBG("Access procedure: %s",
612 wp_context->wispr_msg.access_procedure);
613 if (wp_context->wispr_msg.access_location != NULL)
614 DBG("Access location: %s",
615 wp_context->wispr_msg.access_location);
616 if (wp_context->wispr_msg.location_name != NULL)
617 DBG("Location name: %s",
618 wp_context->wispr_msg.location_name);
619 if (wp_context->wispr_msg.login_url != NULL)
620 DBG("Login URL: %s", wp_context->wispr_msg.login_url);
621 if (wp_context->wispr_msg.abort_login_url != NULL)
622 DBG("Abort login URL: %s",
623 wp_context->wispr_msg.abort_login_url);
624 if (wp_context->wispr_msg.logoff_url != NULL)
625 DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
627 switch (wp_context->wispr_msg.message_type) {
629 DBG("Login required");
631 wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
633 if (__connman_agent_request_login_input(wp_context->service,
634 wispr_portal_request_wispr_login,
635 wp_context) != -EINPROGRESS) {
636 wispr_portal_error(wp_context);
637 free_connman_wispr_portal_context(wp_context);
641 case 120: /* Falling down */
643 if (wp_context->wispr_msg.response_code == 50) {
644 wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
646 g_free(wp_context->wispr_username);
647 wp_context->wispr_username = NULL;
649 g_free(wp_context->wispr_password);
650 wp_context->wispr_password = NULL;
652 g_free(wp_context->wispr_formdata);
653 wp_context->wispr_formdata = NULL;
655 wispr_portal_request_portal(wp_context);
659 wispr_portal_error(wp_context);
669 static gboolean wispr_portal_web_result(GWebResult *result, gpointer user_data)
671 struct connman_wispr_portal_context *wp_context = user_data;
672 const char *redirect = NULL;
673 const guint8 *chunk = NULL;
674 const char *str = NULL;
680 if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
681 g_web_result_get_chunk(result, &chunk, &length);
684 g_web_parser_feed_data(wp_context->wispr_parser,
689 g_web_parser_end_data(wp_context->wispr_parser);
691 if (wp_context->wispr_msg.message_type >= 0) {
692 if (wispr_manage_message(result, wp_context) == TRUE)
697 status = g_web_result_get_status(result);
699 DBG("status: %03u", status);
703 if (wp_context->wispr_msg.message_type >= 0)
706 if (g_web_result_get_header(result, "X-ConnMan-Status",
708 portal_manage_status(result, wp_context);
709 free_connman_wispr_portal_context(wp_context);
713 __connman_agent_request_browser(wp_context->service,
714 wispr_portal_browser_reply_cb,
715 wp_context->redirect_url, wp_context);
719 if (g_web_supports_tls() == FALSE ||
720 g_web_result_get_header(result, "Location",
721 &redirect) == FALSE) {
723 __connman_agent_request_browser(wp_context->service,
724 wispr_portal_browser_reply_cb,
725 wp_context->status_url, wp_context);
729 DBG("Redirect URL: %s", redirect);
731 wp_context->redirect_url = g_strdup(redirect);
733 wp_context->request_id = g_web_request_get(wp_context->web,
734 redirect, wispr_portal_web_result,
735 wispr_route_request, wp_context);
740 if (__connman_service_online_check_failed(wp_context->service,
741 wp_context->type) == 0) {
742 wispr_portal_error(wp_context);
743 free_connman_wispr_portal_context(wp_context);
752 free_wispr_routes(wp_context);
753 wp_context->request_id = 0;
755 wp_context->wispr_msg.message_type = -1;
759 static void proxy_callback(const char *proxy, void *user_data)
761 struct connman_wispr_portal_context *wp_context = user_data;
763 DBG("proxy %s", proxy);
765 if (wp_context == NULL)
768 wp_context->token = 0;
770 if (proxy != NULL && g_strcmp0(proxy, "DIRECT") != 0)
771 g_web_set_proxy(wp_context->web, proxy);
773 g_web_set_accept(wp_context->web, NULL);
774 g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
775 g_web_set_close_connection(wp_context->web, TRUE);
777 connman_wispr_message_init(&wp_context->wispr_msg);
779 wp_context->wispr_parser = g_web_parser_new(
780 "<WISPAccessGatewayParam",
781 "WISPAccessGatewayParam>",
782 xml_wispr_parser_callback, wp_context);
784 wispr_portal_request_portal(wp_context);
787 static gboolean no_proxy_callback(gpointer user_data)
789 struct connman_wispr_portal_context *wp_context = user_data;
791 proxy_callback("DIRECT", wp_context);
796 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
798 enum connman_service_proxy_method proxy_method;
799 enum connman_service_type service_type;
800 char *interface = NULL;
801 char **nameservers = NULL;
806 DBG("wispr/portal context %p", wp_context);
807 DBG("service %p", wp_context->service);
809 service_type = connman_service_get_type(wp_context->service);
811 switch (service_type) {
812 case CONNMAN_SERVICE_TYPE_ETHERNET:
813 case CONNMAN_SERVICE_TYPE_WIFI:
814 case CONNMAN_SERVICE_TYPE_WIMAX:
815 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
816 case CONNMAN_SERVICE_TYPE_CELLULAR:
818 case CONNMAN_SERVICE_TYPE_UNKNOWN:
819 case CONNMAN_SERVICE_TYPE_SYSTEM:
820 case CONNMAN_SERVICE_TYPE_GPS:
821 case CONNMAN_SERVICE_TYPE_VPN:
822 case CONNMAN_SERVICE_TYPE_GADGET:
826 interface = connman_service_get_interface(wp_context->service);
827 if (interface == NULL)
830 DBG("interface %s", interface);
832 if_index = connman_inet_ifindex(interface);
834 DBG("Could not get ifindex");
839 nameservers = connman_service_get_nameservers(wp_context->service);
840 if (nameservers == NULL) {
841 DBG("Could not get nameservers");
846 wp_context->web = g_web_new(if_index);
847 if (wp_context->web == NULL) {
848 DBG("Could not set up GWeb");
853 if (getenv("CONNMAN_WEB_DEBUG"))
854 g_web_set_debug(wp_context->web, web_debug, "WEB");
856 if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
857 g_web_set_address_family(wp_context->web, AF_INET);
858 wp_context->status_url = STATUS_URL_IPV4;
860 g_web_set_address_family(wp_context->web, AF_INET6);
861 wp_context->status_url = STATUS_URL_IPV6;
864 for (i = 0; nameservers[i] != NULL; i++)
865 g_web_add_nameserver(wp_context->web, nameservers[i]);
867 proxy_method = connman_service_get_proxy_method(wp_context->service);
869 if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
870 wp_context->token = connman_proxy_lookup(interface,
871 wp_context->status_url,
873 proxy_callback, wp_context);
875 if (wp_context->token == 0) {
877 free_connman_wispr_portal_context(wp_context);
880 g_timeout_add_seconds(0, no_proxy_callback, wp_context);
884 g_strfreev(nameservers);
890 int __connman_wispr_start(struct connman_service *service,
891 enum connman_ipconfig_type type)
893 struct connman_wispr_portal_context *wp_context = NULL;
894 struct connman_wispr_portal *wispr_portal = NULL;
897 DBG("service %p", service);
899 if (wispr_portal_list == NULL)
902 index = __connman_service_get_index(service);
906 wispr_portal = g_hash_table_lookup(wispr_portal_list,
907 GINT_TO_POINTER(index));
908 if (wispr_portal == NULL) {
909 wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
910 if (wispr_portal == NULL)
913 g_hash_table_replace(wispr_portal_list,
914 GINT_TO_POINTER(index), wispr_portal);
917 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
918 wp_context = wispr_portal->ipv4_context;
919 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
920 wp_context = wispr_portal->ipv6_context;
924 /* If there is already an existing context, we wipe it */
925 if (wp_context != NULL)
926 free_connman_wispr_portal_context(wp_context);
928 wp_context = create_wispr_portal_context();
929 if (wp_context == NULL)
932 connman_service_ref(service);
934 wp_context->service = service;
935 wp_context->type = type;
936 wp_context->wispr_portal = wispr_portal;
938 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
939 wispr_portal->ipv4_context = wp_context;
941 wispr_portal->ipv6_context = wp_context;
943 return wispr_portal_detect(wp_context);
946 void __connman_wispr_stop(struct connman_service *service)
950 DBG("service %p", service);
952 if (wispr_portal_list == NULL)
955 index = __connman_service_get_index(service);
959 g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
962 int __connman_wispr_init(void)
966 wispr_portal_list = g_hash_table_new_full(g_direct_hash,
967 g_direct_equal, NULL,
968 free_connman_wispr_portal);
973 void __connman_wispr_cleanup(void)
977 g_hash_table_destroy(wispr_portal_list);
978 wispr_portal_list = NULL;