forked from openbmc/phosphor-host-ipmid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testaddsel.cpp
117 lines (92 loc) · 2.7 KB
/
testaddsel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "sensorhandler.hpp"
#include <errno.h>
#include <limits.h>
#include <mapper.h>
#include <stdint.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
extern void send_esel(uint16_t recordid);
sd_bus* bus = NULL;
// Use a lookup table to find the interface name of a specific sensor
// This will be used until an alternative is found. this is the first
// step for mapping IPMI
int find_openbmc_path(const uint8_t num, dbus_interface_t* interface)
{
const char* objname = "/org/openbmc/managers/System";
char *str1, *str2, *str3;
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL, *m = NULL;
int r;
char* busname = NULL;
r = mapper_get_service(bus, objname, &busname);
if (r < 0)
{
log<level::ERR>("Failed to get busname", entry("BUS=%s", objname),
entry("ERRNO=0x%X", -r));
goto final;
}
r = sd_bus_message_new_method_call(bus, &m, busname, objname, busname,
"getObjectFromByteId");
if (r < 0)
{
log<level::ERR>("Failed to create a method call",
entry("ERRNO=0x%X", -r));
}
r = sd_bus_message_append(m, "sy", type, num);
if (r < 0)
{
log<level::ERR>("Failed to create a input parameter",
entry("ERRNO=0x%X", -r));
}
// Call the IPMI responder on the bus so the message can be sent to the CEC
r = sd_bus_call(bus, m, 0, &error, &reply);
if (r < 0)
{
log<level::ERR>("Failed to call the method", entry("ERRNO=0x%X", -r));
goto final;
}
r = sd_bus_message_read(reply, "(sss)", &str1, &str2, &str3);
if (r < 0)
{
log<level::ERR>("Failed to get a response", entry("ERRNO=0x%X", -r));
goto final;
}
strncpy(interface->bus, str1, MAX_DBUS_PATH);
strncpy(interface->path, str2, MAX_DBUS_PATH);
strncpy(interface->interface, str3, MAX_DBUS_PATH);
interface->sensornumber = num;
final:
sd_bus_error_free(&error);
sd_bus_message_unref(m);
free(busname);
return r;
}
int main(int argc, char* argv[])
{
int base;
char *endptr, *str;
long val;
uint16_t num;
int r;
if (argc < 2)
{
fprintf(stderr, "Usage: %s sensornumber\n", argv[0]);
return -1;
}
str = argv[1];
base = (argc > 2) ? atoi(argv[2]) : 10;
val = strtol(str, &endptr, base);
num = (uint16_t)val;
/* Connect to system bus */
r = sd_bus_open_system(&bus);
if (r < 0)
{
log<level::ERR>("Failed to connect to system bus",
entry("ERRNO=0x%X", -r));
goto finish;
}
send_esel(num);
finish:
sd_bus_unref(bus);
return 0;
}