2 * Hotspot 2.0 client - Web browser using wpadebug on Android
3 * Copyright (c) 2013, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/eloop.h"
13 #include "wps/http_server.h"
22 static void browser_timeout(void *eloop_data, void *user_ctx)
24 wpa_printf(MSG_INFO, "Timeout on waiting browser interaction to "
30 static void http_req(void *ctx, struct http_request *req)
32 struct browser_data *data = ctx;
37 url = http_request_get_uri(req);
38 wpa_printf(MSG_INFO, "Browser response received: %s", url);
40 if (os_strcmp(url, "/") == 0) {
43 } else if (os_strncmp(url, "/osu/", 5) == 0) {
44 data->success = atoi(url + 5);
48 resp = wpabuf_alloc(100);
50 http_request_deinit(req);
55 wpabuf_put_str(resp, "User input completed");
58 eloop_cancel_timeout(browser_timeout, NULL, NULL);
59 eloop_register_timeout(0, 500000, browser_timeout, &data, NULL);
62 http_request_send_and_deinit(req, resp);
66 int hs20_web_browser(const char *url)
68 struct http_server *http;
70 struct browser_data data;
73 wpa_printf(MSG_INFO, "Launching wpadebug browser to %s", url);
75 os_memset(&data, 0, sizeof(data));
77 if (eloop_init() < 0) {
78 wpa_printf(MSG_ERROR, "eloop_init failed");
81 addr.s_addr = htonl((127 << 24) | 1);
82 http = http_server_init(&addr, 12345, http_req, &data);
84 wpa_printf(MSG_ERROR, "http_server_init failed");
91 wpa_printf(MSG_ERROR, "fork: %s", strerror(errno));
92 http_server_deinit(http);
98 /* run the external command in the child process */
101 argv[0] = "browser-wpadebug";
104 argv[3] = "android.action.MAIN";
106 argv[5] = "android.intent.category.LAUNCHER";
108 argv[7] = "w1.fi.wpadebug/.WpaWebViewActivity";
110 argv[9] = "w1.fi.wpadebug.URL";
111 argv[10] = (void *) url;
113 argv[12] = "-3"; /* USER_CURRENT_OR_SELF */
116 execv("/system/bin/am", argv);
117 wpa_printf(MSG_ERROR, "execv: %s", strerror(errno));
122 eloop_register_timeout(300, 0, browser_timeout, &data, NULL);
124 eloop_cancel_timeout(browser_timeout, &data, NULL);
125 http_server_deinit(http);
128 wpa_printf(MSG_INFO, "Closing Android browser");
129 if (os_exec("/system/bin/am",
130 "start -a android.action.MAIN "
131 "-c android.intent.category.LAUNCHER "
132 "-n w1.fi.wpadebug/.WpaWebViewActivity "
133 "-e w1.fi.wpadebug.URL FINISH", 1) != 0) {
134 wpa_printf(MSG_INFO, "Failed to close wpadebug browser");