#include <talloc/talloc.h>
#include <process/process.h>
+#include <log/log.h>
#include "discover-server.h"
+#include "platform.h"
#include "sysinfo.h"
static struct system_info *sysinfo;
static struct discover_server *server;
-static const char *sysinfo_helper = PKG_LIBEXEC_DIR "/pb-sysinfo";
-
const struct system_info *system_info_get(void)
{
return sysinfo;
}
+bool system_info_network_available(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < sysinfo->n_interfaces; i++)
+ if (sysinfo->interfaces[i]->address)
+ return true;
+ return false;
+}
+
+void system_info_set_interface_address(unsigned int hwaddr_size,
+ uint8_t *hwaddr, const char *address)
+{
+ struct interface_info *if_info;
+ unsigned int i;
+ char mac[20];
+
+ for (i = 0; i < sysinfo->n_interfaces; i++) {
+ if_info = sysinfo->interfaces[i];
+
+ if (if_info->hwaddr_size != hwaddr_size)
+ continue;
+
+ if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
+ continue;
+
+ /* Found an existing interface. Notify clients if a new address
+ * is set */
+ if (!if_info->address || strcmp(if_info->address, address)) {
+ talloc_free(if_info->address);
+ if_info->address = talloc_strdup(if_info, address);
+ discover_server_notify_system_info(server, sysinfo);
+ return;
+ }
+ }
+
+ mac_str(hwaddr, hwaddr_size, mac, sizeof(mac));
+ pb_log("Couldn't find interface matching %s\n", mac);
+}
+
void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
const char *name, bool link)
{
discover_server_notify_system_info(server, sysinfo);
}
-static void system_info_set_identifier(struct system_info *info)
-{
- struct process *process;
- int rc;
- const char *argv[] = {
- sysinfo_helper, NULL, NULL,
- };
-
- process = process_create(info);
- process->path = sysinfo_helper;
- process->argv = argv;
- process->keep_stdout = true;
-
- argv[1] = "--type";
- rc = process_run_sync(process);
-
- if (!rc) {
- info->type = talloc_strndup(info, process->stdout_buf,
- process->stdout_len);
- }
-
- argv[1] = "--id";
- rc = process_run_sync(process);
-
- if (!rc) {
- info->identifier = talloc_strndup(info, process->stdout_buf,
- process->stdout_len);
- }
-
- process_release(process);
-}
-
void system_info_init(struct discover_server *s)
{
server = s;
sysinfo = talloc_zero(server, struct system_info);
- system_info_set_identifier(sysinfo);
+ platform_get_sysinfo(sysinfo);
+}
+
+/* Only reset device information. Platform information is static */
+void system_info_reinit(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < sysinfo->n_blockdevs; i++)
+ talloc_free(sysinfo->blockdevs[i]);
+ talloc_free(sysinfo->blockdevs);
+ sysinfo->blockdevs = NULL;
+ sysinfo->n_blockdevs = 0;
+
+ for (i = 0; i < sysinfo->n_interfaces; i++)
+ talloc_free(sysinfo->interfaces[i]);
+ talloc_free(sysinfo->interfaces);
+ sysinfo->interfaces = NULL;
+ sysinfo->n_interfaces = 0;
}