Add system info messages
[petitboot] / discover / sysinfo.c
1
2 #include <string.h>
3
4 #include <talloc/talloc.h>
5
6 #include "discover-server.h"
7 #include "sysinfo.h"
8
9 static struct system_info *sysinfo;
10 static struct discover_server *server;
11
12 const struct system_info *system_info_get(void)
13 {
14         return sysinfo;
15 }
16
17 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
18                 const char *name)
19 {
20         struct interface_info *if_info;
21         unsigned int i;
22
23         for (i = 0; i < sysinfo->n_interfaces; i++) {
24                 if_info = sysinfo->interfaces[i];
25
26                 if (if_info->hwaddr_size != hwaddr_size)
27                         continue;
28
29                 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
30                         continue;
31
32                 /* update the name and we're done */
33                 talloc_free(if_info->name);
34                 if_info->name = talloc_strdup(if_info, name);
35                 discover_server_notify_system_info(server, sysinfo);
36                 return;
37         }
38
39         if_info = talloc_zero(sysinfo, struct interface_info);
40         if_info->hwaddr_size = hwaddr_size;
41         if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
42         if_info->name = talloc_strdup(if_info, name);
43
44         sysinfo->n_interfaces++;
45         sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
46                                                 struct interface_info *,
47                                                 sysinfo->n_interfaces);
48         sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
49
50         discover_server_notify_system_info(server, sysinfo);
51 }
52
53 static void system_info_set_identifier(struct system_info *info
54                 __attribute__((unused)))
55 {
56         /* todo: call helpers to set type & id */
57 }
58
59 void system_info_init(struct discover_server *s)
60 {
61         sysinfo = talloc_zero(server, struct system_info);
62         server = s;
63         system_info_set_identifier(sysinfo);
64 }