1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

(wifi drivers) Move driver info to userdata

This commit is contained in:
parport0 2020-06-28 23:06:37 +03:00
parent f2728ae0de
commit 8b4e30073a
3 changed files with 106 additions and 90 deletions

View File

@ -20616,31 +20616,31 @@ const char* config_get_wifi_driver_options(void)
void driver_wifi_scan(void)
{
struct rarch_state *p_rarch = &rarch_st;
p_rarch->wifi_driver->scan();
p_rarch->wifi_driver->scan(p_rarch->wifi_data);
}
void driver_wifi_get_ssids(struct string_list* ssids)
{
struct rarch_state *p_rarch = &rarch_st;
p_rarch->wifi_driver->get_ssids(ssids);
p_rarch->wifi_driver->get_ssids(p_rarch->wifi_data, ssids);
}
bool driver_wifi_ssid_is_online(unsigned i)
{
struct rarch_state *p_rarch = &rarch_st;
return p_rarch->wifi_driver->ssid_is_online(i);
return p_rarch->wifi_driver->ssid_is_online(p_rarch->wifi_data, i);
}
bool driver_wifi_connect_ssid(unsigned i, const char* passphrase)
{
struct rarch_state *p_rarch = &rarch_st;
return p_rarch->wifi_driver->connect_ssid(i, passphrase);
return p_rarch->wifi_driver->connect_ssid(p_rarch->wifi_data, i, passphrase);
}
void driver_wifi_tether_start_stop(bool start, char* configfile)
{
struct rarch_state *p_rarch = &rarch_st;
p_rarch->wifi_driver->tether_start_stop(start, configfile);
p_rarch->wifi_driver->tether_start_stop(p_rarch->wifi_data, start, configfile);
}
bool wifi_driver_ctl(enum rarch_wifi_ctl_state state, void *data)
@ -20737,12 +20737,15 @@ bool wifi_driver_ctl(enum rarch_wifi_ctl_state state, void *data)
wifi_driver_ctl(RARCH_WIFI_CTL_FIND_DRIVER, NULL);
p_rarch->wifi_data = p_rarch->wifi_driver->init();
if (!p_rarch->wifi_data)
if (p_rarch->wifi_driver && p_rarch->wifi_driver->init)
{
RARCH_ERR("Failed to initialize wifi driver. Will continue without wifi.\n");
wifi_driver_ctl(RARCH_WIFI_CTL_UNSET_ACTIVE, NULL);
p_rarch->wifi_data = p_rarch->wifi_driver->init();
if (!p_rarch->wifi_data)
{
RARCH_ERR("Failed to initialize wifi driver. Will continue without wifi.\n");
wifi_driver_ctl(RARCH_WIFI_CTL_UNSET_ACTIVE, NULL);
}
}
/*if (wifi_cb.initialized)
@ -33803,6 +33806,9 @@ static void drivers_init(struct rarch_state *p_rarch, int flags)
if (flags & DRIVER_BLUETOOTH_MASK)
bluetooth_driver_ctl(RARCH_BLUETOOTH_CTL_INIT, NULL);
if ((flags & DRIVER_WIFI_MASK))
wifi_driver_ctl(RARCH_WIFI_CTL_INIT, NULL);
if (flags & DRIVER_LOCATION_MASK)
{
/* Only initialize location driver if we're ever going to use it. */

View File

@ -27,26 +27,28 @@
#include "../../gfx/gfx_widgets.h"
#endif
static bool connman_cache[256] = {0};
static unsigned connman_counter = 0;
static struct string_list* lines = NULL;
static char command[256] = {0};
static bool connmanctl_widgets_supported = false;
typedef struct
{
bool connman_cache[256];
unsigned connman_counter;
struct string_list* lines;
char command[256];
bool connmanctl_widgets_supported;
} connman_t;
static void *connmanctl_init(void)
{
connman_t *connman = (connman_t*)calloc(1, sizeof(connman_t));
#ifdef HAVE_GFX_WIDGETS
connmanctl_widgets_supported = gfx_widgets_ready();
connman->connmanctl_widgets_supported = gfx_widgets_ready();
#endif
return (void*)-1;
return connman;
}
static void connmanctl_free(void *data)
{
(void)data;
#ifdef HAVE_GFX_WIDGETS
connmanctl_widgets_supported = gfx_widgets_ready();
#endif
if (data)
free(data);
}
static bool connmanctl_start(void *data)
@ -60,7 +62,7 @@ static void connmanctl_stop(void *data)
(void)data;
}
static bool connmanctl_tether_status(void)
static bool connmanctl_tether_status(connman_t *connman)
{
/* Returns true if the tethering is active
* false when tethering is not active
@ -75,14 +77,14 @@ static bool connmanctl_tether_status(void)
* the matching lines.
* Expected result is either 1 (active) or 0 (not active)
*/
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl technologies | \
grep \"/net/connman/technology/wifi\" -A 10 | \
grep \"^ Tethering =\" -m 1 | \
grep \"True\" | \
wc -l");
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
fgets(ln, sizeof(ln), command_file);
@ -91,7 +93,7 @@ static bool connmanctl_tether_status(void)
ln[ln_size] = '\0';
RARCH_LOG("[CONNMANCTL] Tether Status: command: \"%s\", output: \"%s\"\n",
command, ln);
connman->command, ln);
pclose(command_file);
@ -105,24 +107,24 @@ static bool connmanctl_tether_status(void)
}
static void connmanctl_tether_toggle(
bool switch_on, char* apname, char* passkey)
connman_t *connman, bool switch_on, char* apname, char* passkey)
{
/* Starts / stops the tethering service on wi-fi device */
char output[256] = {0};
FILE *command_file = NULL;
settings_t *settings = config_get_ptr();
#ifdef HAVE_GFX_WIDGETS
bool widgets_active = connmanctl_widgets_supported;
bool widgets_active = connman->connmanctl_widgets_supported;
#endif
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl tether wifi %s %s %s",
switch_on ? "on" : "off", apname, passkey);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
RARCH_LOG("[CONNMANCTL] Tether toggle: command: \"%s\"\n",
command);
connman->command);
while (fgets(output, sizeof(output), command_file))
{
@ -147,38 +149,39 @@ static void connmanctl_tether_toggle(
if (switch_on)
{
if (!connmanctl_tether_status())
if (!connmanctl_tether_status(connman))
configuration_set_bool(settings,
settings->bools.localap_enable, false);
}
else
{
if (connmanctl_tether_status())
if (connmanctl_tether_status(connman))
configuration_set_bool(settings,
settings->bools.localap_enable, true);
}
}
static void connmanctl_scan(void)
static void connmanctl_scan(void *data)
{
char line[512];
union string_list_elem_attr attr;
FILE *serv_file = NULL;
settings_t *settings = config_get_ptr();
connman_t *connman = (connman_t*)data;
attr.i = RARCH_FILETYPE_UNSET;
if (lines)
free(lines);
lines = string_list_new();
if (connman->lines)
free(connman->lines);
connman->lines = string_list_new();
if (connmanctl_tether_status())
if (connmanctl_tether_status(connman))
{
runloop_msg_queue_push(msg_hash_to_str(MSG_LOCALAP_SWITCHING_OFF),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
configuration_set_bool(settings,
settings->bools.localap_enable, false);
connmanctl_tether_toggle(false, "", "");
connmanctl_tether_toggle(connman, false, "", "");
}
pclose(popen("connmanctl enable wifi", "r"));
@ -196,41 +199,43 @@ static void connmanctl_scan(void)
if (len > 0 && line[len-1] == '\n')
line[--len] = '\0';
string_list_append(lines, line, attr);
string_list_append(connman->lines, line, attr);
}
pclose(serv_file);
}
static void connmanctl_get_ssids(struct string_list* ssids)
static void connmanctl_get_ssids(void *data, struct string_list* ssids)
{
unsigned i;
union string_list_elem_attr attr;
attr.i = RARCH_FILETYPE_UNSET;
connman_t *connman = (connman_t*)data;
if (!lines)
if (!connman->lines)
return;
for (i = 0; i < lines->size; i++)
for (i = 0; i < connman->lines->size; i++)
{
char ssid[32];
const char *line = lines->elems[i].data;
const char *line = connman->lines->elems[i].data;
strlcpy(ssid, line+4, sizeof(ssid));
string_list_append(ssids, ssid, attr);
}
}
static bool connmanctl_ssid_is_online(unsigned i)
static bool connmanctl_ssid_is_online(void *data, unsigned i)
{
char ln[512] = {0};
char service[128] = {0};
const char *line = lines->elems[i].data;
connman_t *connman = (connman_t*)data;
const char *line = connman->lines->elems[i].data;
FILE *command_file = NULL;
if (connman_counter == 60)
if (connman->connman_counter == 60)
{
static struct string_list* list = NULL;
connman_counter = 0;
connman->connman_counter = 0;
list = string_split(line, " ");
if (!list)
return false;
@ -244,30 +249,31 @@ static bool connmanctl_ssid_is_online(unsigned i)
strlcpy(service, list->elems[list->size-1].data, sizeof(service));
string_list_free(list);
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl services %s | grep 'State = \\(online\\|ready\\)'",
service);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
while (fgets(ln, 512, command_file))
{
connman_cache[i] = true;
connman->connman_cache[i] = true;
return true;
}
pclose(command_file);
connman_cache[i] = false;
connman->connman_cache[i] = false;
}
else
{
connman_counter++;
return connman_cache[i];
connman->connman_counter++;
return connman->connman_cache[i];
}
return false;
}
static bool connmanctl_connect_ssid(unsigned idx, const char* passphrase)
static bool connmanctl_connect_ssid(
void *data, unsigned idx, const char* passphrase)
{
unsigned i;
char ln[512] = {0};
@ -277,11 +283,12 @@ static bool connmanctl_connect_ssid(unsigned idx, const char* passphrase)
char settings_path[PATH_MAX_LENGTH] = {0};
FILE *command_file = NULL;
FILE *settings_file = NULL;
const char *line = lines->elems[idx].data;
connman_t *connman = (connman_t*)data;
const char *line = connman->lines->elems[idx].data;
settings_t *settings = config_get_ptr();
static struct string_list* list = NULL;
#ifdef HAVE_GFX_WIDGETS
bool widgets_active = connmanctl_widgets_supported;
bool widgets_active = connman->connmanctl_widgets_supported;
#endif
/* connmanctl services outputs a 4 character prefixed lines,
* either whitespace or an identifier. i.e.:
@ -331,23 +338,23 @@ static bool connmanctl_connect_ssid(unsigned idx, const char* passphrase)
fprintf(settings_file, "IPv4.method=%s\n", "dhcp");
fclose(settings_file);
if (connmanctl_tether_status())
if (connmanctl_tether_status(connman))
{
runloop_msg_queue_push(msg_hash_to_str(MSG_LOCALAP_SWITCHING_OFF),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
configuration_set_bool(settings,
settings->bools.localap_enable, false);
connmanctl_tether_toggle(false, "", "");
connmanctl_tether_toggle(connman, false, "", "");
}
pclose(popen("systemctl restart connman", "r"));
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl connect %s 2>&1",
service);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
while (fgets(ln, sizeof(ln), command_file))
{
@ -363,7 +370,8 @@ static bool connmanctl_connect_ssid(unsigned idx, const char* passphrase)
return true;
}
static void connmanctl_get_connected_ssid(char* ssid, size_t buffersize)
static void connmanctl_get_connected_ssid(
connman_t *connman, char* ssid, size_t buffersize)
{
size_t ssid_size;
/* Stores the SSID of the currently connected Wi-Fi
@ -378,13 +386,13 @@ static void connmanctl_get_connected_ssid(char* ssid, size_t buffersize)
* only 'wifi_' services, then greps the one with
* 'R' (Ready) or 'O' (Online) flag and cuts out the ssid
*/
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl services | \
grep wifi_ | \
grep \"^..\\(R\\|O\\)\" | \
cut -d' ' -f 2");
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
fgets(ssid, buffersize, command_file);
@ -397,10 +405,11 @@ static void connmanctl_get_connected_ssid(char* ssid, size_t buffersize)
ssid[ssid_size] = '\0';
RARCH_LOG("[CONNMANCTL] Get Connected SSID: command: \"%s\", output: \"%s\"\n",
command, (ssid_size + 1) ? ssid : "<nothing_found>");
connman->command, (ssid_size + 1) ? ssid : "<nothing_found>");
}
static void connmanctl_get_connected_servicename(char* servicename, size_t buffersize)
static void connmanctl_get_connected_servicename(
connman_t *connman, char* servicename, size_t buffersize)
{
/* Stores the service name of currently connected Wi-Fi
* network in servicename
@ -420,7 +429,7 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
* the next while loop for parsing if the service
* is currently online/ready
*/
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
for serv in %s/wifi_*/ ; do \
if [ -d $serv ] ; then \
basename $serv ; \
@ -428,10 +437,10 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
done",
LAKKA_CONNMAN_DIR);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
RARCH_LOG("[CONNMANCTL] Testing configured services for activity: command: \"%s\"\n",
command);
connman->command);
while (fgets(temp, buffersize, command_file))
{
@ -452,13 +461,13 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
* status and count the lines. Expected results are
* 0 = is not active, 1 = is active
*/
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl services %s | \
grep \"^ State = \\(online\\|ready\\)\" | \
wc -l",
temp);
service_file = popen(command, "r");
service_file = popen(connman->command, "r");
fgets(ln, sizeof(ln), service_file);
ln_size = strlen(ln) - 1;
@ -489,7 +498,7 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
pclose(command_file);
}
static void connmanctl_tether_start_stop(bool start, char* configfile)
static void connmanctl_tether_start_stop(void *data, bool start, char* configfile)
{
/* Start / stop wrapper for the tethering service
* It also checks, if we are currently connected
@ -504,8 +513,9 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
char ln[512] = {0};
char ssid[64] = {0};
char service[256] = {0};
connman_t *connman = (connman_t*)data;
#ifdef HAVE_GFX_WIDGETS
bool widgets_active = connmanctl_widgets_supported;
bool widgets_active = connman->connmanctl_widgets_supported;
#endif
RARCH_LOG("[CONNMANCTL] Tether start stop: begin\n");
@ -514,7 +524,7 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
{
RARCH_LOG("[CONNMANCTL] Tether start stop: request to start access point\n");
if (connmanctl_tether_status()) /* check if already tethering and bail out if so */
if (connmanctl_tether_status(connman)) /* check if already tethering and bail out if so */
{
RARCH_LOG("[CONNMANCTL] Tether start stop: AP already running\n");
runloop_msg_queue_push(msg_hash_to_str(MSG_LOCALAP_ALREADY_RUNNING),
@ -561,17 +571,17 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
RARCH_LOG("[CONNMANCTL] Tether start stop: config \"%s\" exists, reading it\n",
configfile);
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
grep -m 1 \"^APNAME=\" %s | cut -d '=' -f 2- && \
grep -m 1 \"^PASSWORD=\" %s | cut -d '=' -f 2-",
configfile, configfile);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
int i = 0;
RARCH_LOG("[CONNMANCTL] Tether start stop: parsing command: \"%s\"\n",
command);
connman->command);
while (fgets(ln, sizeof(ln), command_file))
{
@ -631,11 +641,11 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
/* check if connected to a wi-fi network */
RARCH_LOG("[CONNMANCTL] Tether start stop: checking if not connected to a wi-fi network...\n");
connmanctl_get_connected_ssid(ssid, sizeof(ssid));
connmanctl_get_connected_ssid(connman, ssid, sizeof(ssid));
if (strlen(ssid) != 0)
{
connmanctl_get_connected_servicename(service, sizeof(service));
connmanctl_get_connected_servicename(connman, service, sizeof(service));
if (strlen(service) != 0)
{
@ -651,14 +661,14 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
snprintf(command, sizeof(command), "\
snprintf(connman->command, sizeof(connman->command), "\
connmanctl disconnect %s",
service);
command_file = popen(command, "r");
command_file = popen(connman->command, "r");
RARCH_LOG("[CONNMANCTL] Tether start stop: disconnecting from service \"%s\", command: \"%s\"\n",
service, command);
service, connman->command);
while (fgets(ln, sizeof(ln), command_file))
{
@ -683,11 +693,11 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
}
}
snprintf(command, sizeof(command),
snprintf(connman->command, sizeof(connman->command),
msg_hash_to_str(MSG_LOCALAP_STARTING),
apname, passkey);
runloop_msg_queue_push(command,
runloop_msg_queue_push(connman->command,
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
}
@ -695,7 +705,7 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
{
RARCH_LOG("[CONNMANCTL] Tether start stop: request to stop access point\n");
if (!connmanctl_tether_status()) /* check if not tethering and when not, bail out */
if (!connmanctl_tether_status(connman)) /* check if not tethering and when not, bail out */
{
RARCH_LOG("[CONNMANCTL] Tether start stop: access point is not running\n");
@ -714,7 +724,7 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
RARCH_LOG("[CONNMANCTL] Tether start stop: calling tether_toggle()\n");
/* call the tether toggle function */
connmanctl_tether_toggle(start, apname, passkey);
connmanctl_tether_toggle(connman, start, apname, passkey);
RARCH_LOG("[CONNMANCTL] Tether start stop: end\n");
}

View File

@ -50,11 +50,11 @@ typedef struct wifi_driver
bool (*start)(void *data);
void (*stop)(void *data);
void (*scan)(void);
void (*get_ssids)(struct string_list *list);
bool (*ssid_is_online)(unsigned i);
bool (*connect_ssid)(unsigned i, const char* passphrase);
void (*tether_start_stop)(bool start, char* configfile);
void (*scan)(void *data);
void (*get_ssids)(void *data, struct string_list *list);
bool (*ssid_is_online)(void *data, unsigned i);
bool (*connect_ssid)(void *data, unsigned i, const char* passphrase);
void (*tether_start_stop)(void *data, bool start, char* configfile);
const char *ident;
} wifi_driver_t;