Skip to content

Commit 6c92dff

Browse files
committed
honor ini file on wifi daemon
Include standard general paths for rc Attend typical configuration from rc file
1 parent a185b70 commit 6c92dff

7 files changed

Lines changed: 194 additions & 105 deletions

File tree

res/miracle-wifid

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ function _miracle-wifid() {
1616
return 0
1717
;;
1818
--log-level)
19-
COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur"))
19+
COMPREPLY=($(compgen -W "fatal alert critical error warning notice info debug trace $(echo {1..8})" -- "$cur"))
2020
return 0
2121
;;
2222
--wpa-loglevel)
23-
COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur"))
23+
COMPREPLY=($(compgen -W "fatal alert critical error warning notice info debug trace $(echo {1..8})" -- "$cur"))
24+
return 0
25+
;;
26+
--go-intent)
27+
COMPREPLY=($(compgen -W "$(echo {0..15})" -- "$cur"))
2428
return 0
2529
;;
2630
esac

res/wpa.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ device_name=my-device
3030

3131
# Device type for desktop systems. Usually better left untouched..
3232
device_type=1-0050F204-1
33-
driver_param=p2p_device=1
33+
driver_param=use_p2p_group_interface=1
3434

3535
# Supported config-methods:
3636
# pbc: Supports Push-Button-Configuration

src/shared/util.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,34 @@
3434
#include <glib.h>
3535

3636
static inline GKeyFile* load_ini_file() {
37-
GKeyFile* gkf = NULL;
38-
gchar* config_file;
39-
40-
gkf = g_key_file_new();
41-
42-
config_file = g_build_filename(g_get_home_dir(), ".config", "miraclecastrc", NULL);
43-
if (!g_key_file_load_from_file(gkf, config_file, G_KEY_FILE_NONE, NULL)) {
44-
g_free(config_file);
45-
config_file = g_build_filename(g_get_home_dir(), ".miraclecast", NULL);
46-
if (!g_key_file_load_from_file(gkf, config_file, G_KEY_FILE_NONE, NULL)) {
47-
g_key_file_free(gkf);
48-
gkf = NULL;
49-
}
50-
}
51-
g_free(config_file);
52-
return gkf;
37+
GKeyFile* gkf = NULL;
38+
gchar* config_file;
39+
40+
const gchar *home_dir = g_get_home_dir();
41+
42+
const gchar *config_paths[][5] = {
43+
{ home_dir, ".miraclecastrc", NULL },
44+
{ home_dir, ".miraclecast", "config", NULL },
45+
{ home_dir, ".config", "miraclecastrc", NULL },
46+
{ home_dir, ".config", "miraclecast", "config", NULL },
47+
{ "/etc", "miraclecastrc", NULL },
48+
{ "/etc", "miraclecast", "config", NULL },
49+
{ NULL }
50+
};
51+
52+
gkf = g_key_file_new();
53+
54+
int i = 0;
55+
for (const gchar **path = config_paths[0]; *path != NULL; path = config_paths[++i]) {
56+
config_file = g_build_filenamev((gchar**)path);
57+
if (g_key_file_load_from_file(gkf, config_file, G_KEY_FILE_NONE, NULL)) {
58+
g_free(config_file);
59+
return gkf;
60+
}
61+
g_free(config_file);
62+
}
63+
g_key_file_free(gkf);
64+
return NULL;
5365
}
5466

5567
static inline void cleanup_sd_bus_message(sd_bus_message **ptr)

src/wifi/wifid-link.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ bool link_is_using_dev(struct link *l)
149149
return l->use_dev;
150150
}
151151

152+
int link_set_driver_param(struct link *l, char *driver_param)
153+
{
154+
char *dp;
155+
156+
if (!driver_param)
157+
return log_EINVAL();
158+
159+
dp = strdup(driver_param);
160+
if (!dp)
161+
return log_ENOMEM();
162+
163+
free(l->driver_param);
164+
l->driver_param = dp;
165+
return 0;
166+
}
167+
152168
int link_set_config_methods(struct link *l, char *config_methods)
153169
{
154170
char *cm;
@@ -165,6 +181,15 @@ int link_set_config_methods(struct link *l, char *config_methods)
165181
return 0;
166182
}
167183

184+
int link_set_go_intent(struct link *l, unsigned int go_intent)
185+
{
186+
if (0 > go_intent || 15 < go_intent)
187+
return log_EINVAL();
188+
189+
l->go_intent = go_intent;
190+
return 0;
191+
}
192+
168193
int link_set_ip_binary(struct link *l, const char *ip_binary)
169194
{
170195
char *ipb;

src/wifi/wifid-supplicant.c

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,13 +2422,13 @@ static void supplicant_run(struct supplicant *s, const char *binary)
24222422
argv[i++] = (char*)binary;
24232423

24242424
/* debugging? */
2425-
if (arg_wpa_loglevel >= LOG_DEBUG)
2425+
if (wpa_loglevel >= LOG_DEBUG)
24262426
argv[i++] = "-dd";
2427-
else if (arg_wpa_loglevel >= LOG_INFO)
2427+
else if (wpa_loglevel >= LOG_INFO)
24282428
argv[i++] = "-d";
2429-
else if (arg_wpa_loglevel < LOG_ERROR)
2429+
else if (wpa_loglevel < LOG_ERROR)
24302430
argv[i++] = "-qq";
2431-
else if (arg_wpa_loglevel < LOG_NOTICE)
2431+
else if (wpa_loglevel < LOG_NOTICE)
24322432
argv[i++] = "-q";
24332433

24342434
argv[i++] = "-c";
@@ -2440,7 +2440,7 @@ static void supplicant_run(struct supplicant *s, const char *binary)
24402440
argv[i++] = "-g";
24412441
argv[i++] = s->global_ctrl;
24422442

2443-
if (arg_wpa_syslog) {
2443+
if (wpa_syslog) {
24442444
argv[i++] = "-s";
24452445
}
24462446

@@ -2452,45 +2452,45 @@ static void supplicant_run(struct supplicant *s, const char *binary)
24522452

24532453
static int supplicant_find(char **binary)
24542454
{
2455-
_shl_free_ char *path = getenv("PATH");
2456-
if(!path) {
2457-
return -EINVAL;
2458-
}
2455+
_shl_free_ char *path = getenv("PATH");
2456+
if(!path) {
2457+
return -EINVAL;
2458+
}
24592459

2460-
path = strdup(path);
2461-
if(!path) {
2462-
return log_ENOMEM();
2463-
}
2460+
path = strdup(path);
2461+
if(!path) {
2462+
return log_ENOMEM();
2463+
}
2464+
2465+
struct stat bin_stat;
2466+
char *curr = path, *next;
2467+
while(1) {
2468+
curr = strtok_r(curr, ":", &next);
2469+
if(!curr) {
2470+
break;
2471+
}
2472+
2473+
_shl_free_ char *bin = shl_strcat(curr, "/wpa_supplicant");
2474+
if (!bin)
2475+
return log_ENOMEM();
2476+
2477+
if(stat(bin, &bin_stat) < 0) {
2478+
if(ENOENT == errno || ENOTDIR == errno) {
2479+
goto end;
2480+
}
2481+
return log_ERRNO();
2482+
}
24642483

2465-
struct stat bin_stat;
2466-
char *curr = path, *next;
2467-
while(1) {
2468-
curr = strtok_r(curr, ":", &next);
2469-
if(!curr) {
2470-
break;
2471-
}
2472-
2473-
_shl_free_ char *bin = shl_strcat(curr, "/wpa_supplicant");
2474-
if (!bin)
2475-
return log_ENOMEM();
2476-
2477-
if(stat(bin, &bin_stat) < 0) {
2478-
if(ENOENT == errno || ENOTDIR == errno) {
2479-
goto end;
2480-
}
2481-
return log_ERRNO();
2482-
}
2483-
2484-
if (!access(bin, X_OK)) {
2485-
*binary = strdup(bin);
2486-
return 0;
2487-
}
2484+
if (!access(bin, X_OK)) {
2485+
*binary = strdup(bin);
2486+
return 0;
2487+
}
24882488

24892489
end:
2490-
curr = NULL;
2491-
}
2490+
curr = NULL;
2491+
}
24922492

2493-
return -EINVAL;
2493+
return -EINVAL;
24942494
}
24952495

24962496
static int supplicant_spawn(struct supplicant *s)
@@ -2506,16 +2506,16 @@ static int supplicant_spawn(struct supplicant *s)
25062506

25072507
log_debug("spawn supplicant of %s", s->l->ifname);
25082508

2509-
if (supplicant_find(&binary) < 0) {
2510-
if (binary != NULL) {
2511-
log_error("execution of wpas (%s) not possible: %m", binary);
2512-
} else {
2513-
log_error("execution of wpas not possible: %m");
2509+
if (supplicant_find(&binary) < 0) {
2510+
if (binary != NULL) {
2511+
log_error("execution of wpas (%s) not possible: %m", binary);
2512+
} else {
2513+
log_error("execution of wpas not possible: %m");
2514+
}
2515+
return -EINVAL;
25142516
}
2515-
return -EINVAL;
2516-
}
25172517

2518-
log_info("wpa_supplicant found: %s", binary);
2518+
log_info("wpa_supplicant found: %s", binary);
25192519

25202520
pid = fork();
25212521
if (pid < 0) {
@@ -2623,18 +2623,21 @@ static int supplicant_write_config(struct supplicant *s)
26232623
return log_ERRNO();
26242624

26252625
r = fprintf(f,
2626-
"# Generated configuration - DO NOT EDIT!\n"
2627-
"device_name=%s\n"
2628-
"device_type=%s\n"
2629-
"config_methods=%s\n"
2630-
"driver_param=%s\n"
2631-
"ap_scan=%s\n"
2632-
"# End of configuration\n",
2633-
s->l->friendly_name ?: "unknown",
2634-
"1-0050F204-1",
2635-
s->l->config_methods ?: "pbc",
2636-
"p2p_device=1",
2637-
"1");
2626+
"# Generated configuration - DO NOT EDIT!\n"
2627+
"device_name=%s\n"
2628+
"device_type=%s\n"
2629+
"config_methods=%s\n"
2630+
"driver_param=%s\n"
2631+
"ap_scan=%s\n"
2632+
"p2p_go_intent=%d\n"
2633+
"# End of configuration\n",
2634+
2635+
s->l->friendly_name ?: "unknown",
2636+
"1-0050F204-1",
2637+
s->l->config_methods ?: "pbc",
2638+
s->l->driver_param ?: "",
2639+
"1",
2640+
s->l->go_intent ?: 0);
26382641
if (r < 0) {
26392642
r = log_ERRNO();
26402643
fclose(f);

0 commit comments

Comments
 (0)