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