2012-10-21 10:26:52 +00:00
|
|
|
/* ipxwrapper - Configuration header
|
|
|
|
* Copyright (C) 2011 Daniel Collins <solemnwarning@solemnwarning.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "common.h"
|
2012-11-10 19:55:59 +00:00
|
|
|
#include "interface.h"
|
2012-10-21 10:26:52 +00:00
|
|
|
|
|
|
|
main_config_t get_main_config(void)
|
|
|
|
{
|
|
|
|
/* Defaults */
|
|
|
|
|
|
|
|
main_config_t config;
|
|
|
|
|
2012-10-21 10:33:20 +00:00
|
|
|
config.udp_port = DEFAULT_PORT;
|
|
|
|
config.w95_bug = true;
|
2012-10-21 10:26:52 +00:00
|
|
|
|
|
|
|
HKEY reg = reg_open_main(false);
|
|
|
|
DWORD version = reg_get_dword(reg, "config_version", 1);
|
|
|
|
|
|
|
|
if(version == 1)
|
|
|
|
{
|
|
|
|
struct v1_global_config reg_config;
|
|
|
|
|
|
|
|
if(reg_get_bin(reg, "global", ®_config, sizeof(reg_config), NULL))
|
|
|
|
{
|
|
|
|
config.udp_port = reg_config.udp_port;
|
|
|
|
config.w95_bug = reg_config.w95_bug;
|
|
|
|
}
|
2012-10-28 12:57:28 +00:00
|
|
|
|
2012-10-28 15:53:54 +00:00
|
|
|
config.log_level = reg_get_dword(reg, "min_log_level", LOG_INFO);
|
2012-10-21 10:26:52 +00:00
|
|
|
}
|
|
|
|
else if(version == 2)
|
|
|
|
{
|
2012-11-11 20:58:56 +00:00
|
|
|
config.udp_port = reg_get_dword(reg, "port", config.udp_port);
|
|
|
|
config.w95_bug = reg_get_dword(reg, "w95_bug", config.w95_bug);
|
2012-10-28 15:53:54 +00:00
|
|
|
|
|
|
|
config.log_level = reg_get_dword(reg, "log_level", LOG_INFO);
|
2012-10-21 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reg_close(reg);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2012-10-28 15:53:54 +00:00
|
|
|
bool set_main_config(const main_config_t *config)
|
|
|
|
{
|
|
|
|
HKEY reg = reg_open_main(true);
|
|
|
|
|
2012-11-10 22:24:47 +00:00
|
|
|
bool ok = reg_set_dword(reg, "port", config->udp_port)
|
2012-10-28 15:53:54 +00:00
|
|
|
&& reg_set_dword(reg, "w95_bug", config->w95_bug)
|
|
|
|
|
|
|
|
&& reg_set_dword(reg, "log_level", config->log_level)
|
|
|
|
|
|
|
|
&& reg_set_dword(reg, "version", 2);
|
|
|
|
|
|
|
|
reg_close(reg);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2012-10-21 10:26:52 +00:00
|
|
|
iface_config_t get_iface_config(addr48_t hwaddr)
|
|
|
|
{
|
|
|
|
char id[18];
|
|
|
|
addr48_string(id, hwaddr);
|
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
iface_config_t config = {
|
|
|
|
.netnum = addr32_in((unsigned char[]){0x00, 0x00, 0x00, 0x01}),
|
|
|
|
.nodenum = hwaddr,
|
|
|
|
|
|
|
|
.enabled = true
|
|
|
|
};
|
2012-10-21 10:26:52 +00:00
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
HKEY reg = reg_open_main(false);
|
|
|
|
HKEY ifreg = reg_open_subkey(reg, id, false);
|
2012-10-21 10:26:52 +00:00
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
if(ifreg)
|
2012-10-21 10:26:52 +00:00
|
|
|
{
|
2012-11-10 19:55:59 +00:00
|
|
|
config.netnum = reg_get_addr32(ifreg, "net", config.netnum);
|
|
|
|
config.nodenum = reg_get_addr48(ifreg, "node", config.nodenum);
|
|
|
|
config.enabled = reg_get_dword(ifreg, "enabled", config.enabled);
|
|
|
|
}
|
|
|
|
else{
|
2012-10-21 10:26:52 +00:00
|
|
|
struct v1_iface_config reg_config;
|
|
|
|
|
|
|
|
if(reg_get_bin(reg, id, ®_config, sizeof(reg_config), NULL))
|
|
|
|
{
|
|
|
|
config.netnum = addr32_in(reg_config.ipx_net);
|
|
|
|
config.nodenum = addr48_in(reg_config.ipx_node);
|
|
|
|
config.enabled = reg_config.enabled;
|
|
|
|
}
|
|
|
|
}
|
2012-11-10 19:55:59 +00:00
|
|
|
|
|
|
|
if(hwaddr == WILDCARD_IFACE_HWADDR && config.nodenum == hwaddr)
|
2012-10-21 10:26:52 +00:00
|
|
|
{
|
2012-11-10 19:55:59 +00:00
|
|
|
/* Generate a random node number for the wildcard interface and
|
|
|
|
* store it in the registry for persistence.
|
|
|
|
*/
|
2012-10-21 10:26:52 +00:00
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
config.nodenum = gen_random_mac();
|
2012-10-21 10:26:52 +00:00
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
set_iface_config(hwaddr, &config);
|
2012-10-21 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 19:55:59 +00:00
|
|
|
reg_close(ifreg);
|
2012-10-21 10:26:52 +00:00
|
|
|
reg_close(reg);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2012-10-28 15:53:54 +00:00
|
|
|
bool set_iface_config(addr48_t hwaddr, const iface_config_t *config)
|
|
|
|
{
|
|
|
|
char id[ADDR48_STRING_SIZE];
|
|
|
|
addr48_string(id, hwaddr);
|
|
|
|
|
|
|
|
HKEY reg = reg_open_main(false);
|
|
|
|
HKEY ifreg = reg_open_subkey(reg, id, true);
|
|
|
|
|
|
|
|
bool ok = reg_set_addr32(ifreg, "net", config->netnum)
|
2012-11-10 19:55:59 +00:00
|
|
|
&& reg_set_addr48(ifreg, "node", config->nodenum)
|
|
|
|
&& reg_set_dword(ifreg, "enabled", config->enabled);
|
2012-10-28 15:53:54 +00:00
|
|
|
|
|
|
|
reg_close(ifreg);
|
|
|
|
reg_close(reg);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2012-10-21 10:26:52 +00:00
|
|
|
addr48_t get_primary_iface(void)
|
|
|
|
{
|
|
|
|
addr48_t primary = addr48_in((unsigned char[]){ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
|
|
|
|
|
|
|
|
HKEY reg = reg_open_main(false);
|
|
|
|
DWORD version = reg_get_dword(reg, "config_version", 1);
|
|
|
|
|
|
|
|
if(version == 1)
|
|
|
|
{
|
|
|
|
/* TODO: Iterate... */
|
|
|
|
}
|
|
|
|
else if(version == 2)
|
|
|
|
{
|
|
|
|
primary = reg_get_addr48(reg, "primary", primary);
|
|
|
|
}
|
|
|
|
|
|
|
|
reg_close(reg);
|
|
|
|
|
|
|
|
return primary;
|
|
|
|
}
|