vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <dlfcn.h> |
| 3 | #include <iostream> |
| 4 | #include <unistd.h> |
| 5 | #include <assert.h> |
| 6 | #include <dirent.h> |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 7 | #include <systemd/sd-bus.h> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <map> |
| 11 | #include "ipmid.H" |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 12 | #include <sys/time.h> |
| 13 | #include <errno.h> |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 14 | #include "sensorhandler.h" |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 15 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 16 | sd_bus *bus = NULL; |
vishwa | b9f559a | 2016-01-13 01:53:08 -0600 | [diff] [blame] | 17 | sd_bus_slot *ipmid_slot = NULL; |
Chris Austen | 30195fa | 2015-11-13 14:39:19 -0600 | [diff] [blame] | 18 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 19 | FILE *ipmiio, *ipmidbus, *ipmicmddetails; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 20 | |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 21 | void print_usage(void) { |
| 22 | fprintf(stderr, "Options: [-d mask]\n"); |
| 23 | fprintf(stderr, " mask : 0x01 - Print ipmi packets\n"); |
| 24 | fprintf(stderr, " mask : 0x02 - Print DBUS operations\n"); |
| 25 | fprintf(stderr, " mask : 0x04 - Print ipmi command details\n"); |
| 26 | fprintf(stderr, " mask : 0xFF - Print all trace\n"); |
| 27 | } |
| 28 | |
Jeremy Kerr | e41081f | 2015-10-27 12:11:36 +0800 | [diff] [blame] | 29 | const char * DBUS_INTF = "org.openbmc.HostIpmi"; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 30 | |
Jeremy Kerr | e41081f | 2015-10-27 12:11:36 +0800 | [diff] [blame] | 31 | const char * FILTER = "type='signal',interface='org.openbmc.HostIpmi',member='ReceivedMessage'"; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 32 | |
| 33 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 34 | typedef std::pair<ipmi_netfn_t, ipmi_cmd_t> ipmi_fn_cmd_t; |
| 35 | typedef std::pair<ipmid_callback_t, ipmi_context_t> ipmi_fn_context_t; |
| 36 | |
| 37 | // Global data structure that contains the IPMI command handler's registrations. |
| 38 | std::map<ipmi_fn_cmd_t, ipmi_fn_context_t> g_ipmid_router_map; |
| 39 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 40 | // IPMI Spec, shared Reservation ID. |
| 41 | unsigned short g_sel_reserve = 0xFFFF; |
| 42 | |
| 43 | unsigned short get_sel_reserve_id(void) |
| 44 | { |
| 45 | return g_sel_reserve; |
| 46 | } |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 47 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 48 | #ifndef HEXDUMP_COLS |
| 49 | #define HEXDUMP_COLS 16 |
| 50 | #endif |
| 51 | |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 52 | void hexdump(FILE *s, void *mem, size_t len) |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 53 | { |
| 54 | unsigned int i, j; |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 55 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 56 | for(i = 0; i < len + ((len % HEXDUMP_COLS) ? (HEXDUMP_COLS - len % HEXDUMP_COLS) : 0); i++) |
| 57 | { |
| 58 | /* print offset */ |
| 59 | if(i % HEXDUMP_COLS == 0) |
| 60 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 61 | fprintf(s,"0x%06x: ", i); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 62 | } |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 63 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 64 | /* print hex data */ |
| 65 | if(i < len) |
| 66 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 67 | fprintf(s,"%02x ", 0xFF & ((char*)mem)[i]); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 68 | } |
| 69 | else /* end of block, just aligning for ASCII dump */ |
| 70 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 71 | fprintf(s," "); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 72 | } |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 73 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 74 | /* print ASCII dump */ |
| 75 | if(i % HEXDUMP_COLS == (HEXDUMP_COLS - 1)) |
| 76 | { |
| 77 | for(j = i - (HEXDUMP_COLS - 1); j <= i; j++) |
| 78 | { |
| 79 | if(j >= len) /* end of block, not really printing */ |
| 80 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 81 | fputc(' ', s); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 82 | } |
| 83 | else if(isprint(((char*)mem)[j])) /* printable char */ |
| 84 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 85 | fputc(0xFF & ((char*)mem)[j], s); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 86 | } |
| 87 | else /* other char */ |
| 88 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 89 | fputc('.',s); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 92 | fputc('\n',s); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 98 | // Method that gets called by shared libraries to get their command handlers registered |
| 99 | void ipmi_register_callback(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 100 | ipmi_context_t context, ipmid_callback_t handler) |
| 101 | { |
| 102 | // Pack NetFn and Command in one. |
| 103 | auto netfn_and_cmd = std::make_pair(netfn, cmd); |
| 104 | |
| 105 | // Pack Function handler and Data in another. |
| 106 | auto handler_and_context = std::make_pair(handler, context); |
| 107 | |
| 108 | // Check if the registration has already been made.. |
| 109 | auto iter = g_ipmid_router_map.find(netfn_and_cmd); |
| 110 | if(iter != g_ipmid_router_map.end()) |
| 111 | { |
| 112 | fprintf(stderr,"ERROR : Duplicate registration for NetFn [0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | // This is a fresh registration.. Add it to the map. |
| 117 | g_ipmid_router_map.emplace(netfn_and_cmd, handler_and_context); |
| 118 | } |
| 119 | |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | // Looks at the map and calls corresponding handler functions. |
| 124 | ipmi_ret_t ipmi_netfn_router(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, |
| 125 | ipmi_response_t response, ipmi_data_len_t data_len) |
| 126 | { |
| 127 | // return from the Command handlers. |
| 128 | ipmi_ret_t rc = IPMI_CC_INVALID; |
| 129 | |
| 130 | // Walk the map that has the registered handlers and invoke the approprite |
| 131 | // handlers for matching commands. |
| 132 | auto iter = g_ipmid_router_map.find(std::make_pair(netfn, cmd)); |
| 133 | if(iter == g_ipmid_router_map.end()) |
| 134 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 135 | fprintf(stderr, "No registered handlers for NetFn:[0x%X], Cmd:[0x%X]" |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 136 | " trying Wilcard implementation \n",netfn, cmd); |
| 137 | |
| 138 | // Now that we did not find any specific [NetFn,Cmd], tuple, check for |
| 139 | // NetFn, WildCard command present. |
| 140 | iter = g_ipmid_router_map.find(std::make_pair(netfn, IPMI_CMD_WILDCARD)); |
| 141 | if(iter == g_ipmid_router_map.end()) |
| 142 | { |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 143 | fprintf(stderr, "No Registered handlers for NetFn:[0x%X],Cmd:[0x%X]\n",netfn, IPMI_CMD_WILDCARD); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 144 | |
| 145 | // Respond with a 0xC1 |
| 146 | memcpy(response, &rc, IPMI_CC_LEN); |
| 147 | *data_len = IPMI_CC_LEN; |
| 148 | return rc; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | #ifdef __IPMI_DEBUG__ |
| 153 | // We have either a perfect match -OR- a wild card atleast, |
| 154 | printf("Calling Net function:[0x%X], Command:[0x%X]\n", netfn, cmd); |
| 155 | #endif |
| 156 | |
| 157 | // Extract the map data onto appropriate containers |
| 158 | auto handler_and_context = iter->second; |
| 159 | |
| 160 | // Creating a pointer type casted to char* to make sure we advance 1 byte |
| 161 | // when we advance pointer to next's address. advancing void * would not |
| 162 | // make sense. |
| 163 | char *respo = &((char *)response)[IPMI_CC_LEN]; |
| 164 | |
| 165 | // Response message from the plugin goes into a byte post the base response |
| 166 | rc = (handler_and_context.first) (netfn, cmd, request, respo, |
| 167 | data_len, handler_and_context.second); |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 168 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 169 | // Now copy the return code that we got from handler and pack it in first |
| 170 | // byte. |
| 171 | memcpy(response, &rc, IPMI_CC_LEN); |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 172 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 173 | // Data length is now actual data + completion code. |
| 174 | *data_len = *data_len + IPMI_CC_LEN; |
| 175 | |
| 176 | return rc; |
| 177 | } |
| 178 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 179 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 180 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 181 | |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 182 | static int send_ipmi_message(sd_bus_message *req, unsigned char seq, unsigned char netfn, unsigned char lun, unsigned char cmd, unsigned char cc, unsigned char *buf, unsigned char len) { |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 183 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 184 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 185 | sd_bus_message *reply = NULL, *m=NULL; |
Jeremy Kerr | e41081f | 2015-10-27 12:11:36 +0800 | [diff] [blame] | 186 | const char *dest, *path; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 187 | int r, pty; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 188 | |
Jeremy Kerr | e41081f | 2015-10-27 12:11:36 +0800 | [diff] [blame] | 189 | dest = sd_bus_message_get_sender(req); |
| 190 | path = sd_bus_message_get_path(req); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 191 | |
Jeremy Kerr | e41081f | 2015-10-27 12:11:36 +0800 | [diff] [blame] | 192 | r = sd_bus_message_new_method_call(bus,&m,dest,path,DBUS_INTF,"sendMessage"); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 193 | if (r < 0) { |
| 194 | fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r)); |
| 195 | return -1; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 196 | } |
| 197 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 198 | |
Chris Austen | abfb5e8 | 2015-10-13 12:29:24 -0500 | [diff] [blame] | 199 | // Responses in IPMI require a bit set. So there ya go... |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 200 | netfn |= 0x01; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 201 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 202 | |
| 203 | // Add the bytes needed for the methods to be called |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 204 | r = sd_bus_message_append(m, "yyyyy", seq, netfn, lun, cmd, cc); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 205 | if (r < 0) { |
| 206 | fprintf(stderr, "Failed add the netfn and others : %s\n", strerror(-r)); |
Chris Austen | 169395e | 2015-12-02 20:56:15 -0600 | [diff] [blame] | 207 | goto final; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 208 | } |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 209 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 210 | r = sd_bus_message_append_array(m, 'y', buf, len); |
| 211 | if (r < 0) { |
| 212 | fprintf(stderr, "Failed to add the string of response bytes: %s\n", strerror(-r)); |
Chris Austen | 169395e | 2015-12-02 20:56:15 -0600 | [diff] [blame] | 213 | goto final; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | |
| 218 | // Call the IPMI responder on the bus so the message can be sent to the CEC |
| 219 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 220 | if (r < 0) { |
Chris Austen | 169395e | 2015-12-02 20:56:15 -0600 | [diff] [blame] | 221 | fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); |
Chris Austen | 6bd2396 | 2015-12-07 21:31:48 -0600 | [diff] [blame] | 222 | fprintf(stderr, "Dest: %s, Path: %s\n", dest, path); |
Chris Austen | 169395e | 2015-12-02 20:56:15 -0600 | [diff] [blame] | 223 | goto final; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | r = sd_bus_message_read(reply, "x", &pty); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 227 | if (r < 0) { |
| 228 | fprintf(stderr, "Failed to get a rc from the method: %s\n", strerror(-r)); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Chris Austen | 169395e | 2015-12-02 20:56:15 -0600 | [diff] [blame] | 231 | final: |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 232 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 233 | m = sd_bus_message_unref(m); |
| 234 | reply = sd_bus_message_unref(reply); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 235 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 236 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int handle_ipmi_command(sd_bus_message *m, void *user_data, sd_bus_error |
| 240 | *ret_error) { |
| 241 | int r = 0; |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 242 | unsigned char sequence, netfn, lun, cmd; |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 243 | const void *request; |
| 244 | size_t sz; |
| 245 | size_t resplen =MAX_IPMI_BUFFER; |
| 246 | unsigned char response[MAX_IPMI_BUFFER]; |
| 247 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 248 | memset(response, 0, MAX_IPMI_BUFFER); |
| 249 | |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 250 | r = sd_bus_message_read(m, "yyyy", &sequence, &netfn, &lun, &cmd); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 251 | if (r < 0) { |
| 252 | fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r)); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | r = sd_bus_message_read_array(m, 'y', &request, &sz ); |
| 257 | if (r < 0) { |
| 258 | fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r)); |
| 259 | return -1; |
| 260 | } |
| 261 | |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 262 | fprintf(ipmiio, "IPMI Incoming: Seq 0x%02x, NetFn 0x%02x, CMD: 0x%02x \n", sequence, netfn, cmd); |
| 263 | hexdump(ipmiio, (void*)request, sz); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 264 | |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 265 | // Allow the length field to be used for both input and output of the |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 266 | // ipmi call |
| 267 | resplen = sz; |
| 268 | |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 269 | // Now that we have parsed the entire byte array from the caller |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 270 | // we can call the ipmi router to do the work... |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 271 | r = ipmi_netfn_router(netfn, cmd, (void *)request, (void *)response, &resplen); |
| 272 | if(r != 0) |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 273 | { |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 274 | fprintf(stderr,"ERROR:[0x%X] handling NetFn:[0x%X], Cmd:[0x%X]\n",r, netfn, cmd); |
Nan Li | 80be4b9 | 2016-05-23 19:30:49 +0800 | [diff] [blame] | 275 | |
| 276 | if(r == -1) { |
| 277 | response[0] = IPMI_CC_UNSPECIFIED_ERROR; |
| 278 | } |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 279 | } |
| 280 | |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 281 | fprintf(ipmiio, "IPMI Response:\n"); |
| 282 | hexdump(ipmiio, (void*)response, resplen); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 283 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 284 | // Send the response buffer from the ipmi command |
Jeremy Kerr | 2564b1a | 2015-10-27 13:37:17 +0800 | [diff] [blame] | 285 | r = send_ipmi_message(m, sequence, netfn, lun, cmd, response[0], |
| 286 | ((unsigned char *)response) + 1, resplen - 1); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 287 | if (r < 0) { |
| 288 | fprintf(stderr, "Failed to send the response message\n"); |
| 289 | return -1; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 290 | } |
| 291 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 292 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 293 | return 0; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 294 | } |
| 295 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 296 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 297 | //---------------------------------------------------------------------- |
| 298 | // handler_select |
| 299 | // Select all the files ending with with .so. in the given diretcory |
| 300 | // @d: dirent structure containing the file name |
| 301 | //---------------------------------------------------------------------- |
| 302 | int handler_select(const struct dirent *entry) |
| 303 | { |
| 304 | // To hold ".so" from entry->d_name; |
| 305 | char dname_copy[4] = {0}; |
| 306 | |
| 307 | // We want to avoid checking for everything and isolate to the ones having |
| 308 | // .so in them. |
| 309 | if(strstr(entry->d_name, IPMI_PLUGIN_EXTN)) |
| 310 | { |
| 311 | // It is possible that .so could be anywhere in the string but unlikely |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 312 | // But being careful here. Get the base address of the string, move |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 313 | // until end and come back 3 steps and that gets what we need. |
| 314 | strcpy(dname_copy, (entry->d_name + strlen(entry->d_name)-strlen(IPMI_PLUGIN_EXTN))); |
| 315 | if(strcmp(dname_copy, IPMI_PLUGIN_EXTN) == 0) |
| 316 | { |
| 317 | return 1; |
| 318 | } |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | // This will do a dlopen of every .so in ipmi_lib_path and will dlopen everything so that they will |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 324 | // register a callback handler |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 325 | void ipmi_register_callback_handlers(const char* ipmi_lib_path) |
| 326 | { |
| 327 | // For walking the ipmi_lib_path |
| 328 | struct dirent **handler_list; |
| 329 | int num_handlers = 0; |
| 330 | |
| 331 | // This is used to check and abort if someone tries to register a bad one. |
| 332 | void *lib_handler = NULL; |
| 333 | |
| 334 | if(ipmi_lib_path == NULL) |
| 335 | { |
| 336 | fprintf(stderr,"ERROR; No handlers to be registered for ipmi.. Aborting\n"); |
| 337 | assert(0); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | // 1: Open ipmi_lib_path. Its usually "/usr/lib/phosphor-host-ipmid" |
| 342 | // 2: Scan the directory for the files that end with .so |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 343 | // 3: For each one of them, just do a 'dlopen' so that they register |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 344 | // the handlers for callback routines. |
| 345 | |
| 346 | std::string handler_fqdn = ipmi_lib_path; |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 347 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 348 | // Append a "/" since we need to add the name of the .so. If there is |
| 349 | // already a .so, adding one more is not any harm. |
| 350 | handler_fqdn += "/"; |
| 351 | |
| 352 | num_handlers = scandir(ipmi_lib_path, &handler_list, handler_select, alphasort); |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 353 | if (num_handlers < 0) |
| 354 | return; |
Jeremy Kerr | 5e8f85e | 2015-10-27 13:43:54 +0800 | [diff] [blame] | 355 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 356 | while(num_handlers--) |
| 357 | { |
Chris Austen | 5403026 | 2015-10-13 12:30:46 -0500 | [diff] [blame] | 358 | handler_fqdn = ipmi_lib_path; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 359 | handler_fqdn += handler_list[num_handlers]->d_name; |
Chris Austen | 5403026 | 2015-10-13 12:30:46 -0500 | [diff] [blame] | 360 | printf("Registering handler:[%s]\n",handler_fqdn.c_str()); |
| 361 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 362 | lib_handler = dlopen(handler_fqdn.c_str(), RTLD_NOW); |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 363 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 364 | if(lib_handler == NULL) |
| 365 | { |
Chris Austen | 120f732 | 2015-10-14 23:27:31 -0500 | [diff] [blame] | 366 | fprintf(stderr,"ERROR opening [%s]: %s\n", |
| 367 | handler_fqdn.c_str(), dlerror()); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 368 | } |
| 369 | // Wipe the memory allocated for this particular entry. |
| 370 | free(handler_list[num_handlers]); |
| 371 | } |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 372 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 373 | // Done with all registration. |
| 374 | free(handler_list); |
| 375 | } |
| 376 | |
| 377 | // TODO : What to be done on the memory that is given by dlopen ?. |
| 378 | return; |
| 379 | } |
| 380 | |
Chris Austen | 30195fa | 2015-11-13 14:39:19 -0600 | [diff] [blame] | 381 | sd_bus *ipmid_get_sd_bus_connection(void) { |
| 382 | return bus; |
| 383 | } |
| 384 | |
vishwa | b9f559a | 2016-01-13 01:53:08 -0600 | [diff] [blame] | 385 | sd_bus_slot *ipmid_get_sd_bus_slot(void) { |
| 386 | return ipmid_slot; |
| 387 | } |
| 388 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 389 | int main(int argc, char *argv[]) |
| 390 | { |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 391 | int r; |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 392 | unsigned long tvalue; |
| 393 | int c; |
| 394 | |
| 395 | |
| 396 | |
| 397 | // This file and subsequient switch is for turning on levels |
| 398 | // of trace |
| 399 | ipmicmddetails = ipmiio = ipmidbus = fopen("/dev/null", "w"); |
| 400 | |
| 401 | while ((c = getopt (argc, argv, "h:d:")) != -1) |
| 402 | switch (c) { |
| 403 | case 'd': |
| 404 | tvalue = strtoul(optarg, NULL, 16); |
| 405 | if (1&tvalue) { |
| 406 | ipmiio = stdout; |
| 407 | } |
| 408 | if (2&tvalue) { |
| 409 | ipmidbus = stdout; |
| 410 | } |
| 411 | if (4&tvalue) { |
| 412 | ipmicmddetails = stdout; |
| 413 | } |
| 414 | break; |
| 415 | case 'h': |
| 416 | case '?': |
| 417 | print_usage(); |
| 418 | return 1; |
| 419 | } |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 420 | |
| 421 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 422 | /* Connect to system bus */ |
| 423 | r = sd_bus_open_system(&bus); |
| 424 | if (r < 0) { |
| 425 | fprintf(stderr, "Failed to connect to system bus: %s\n", |
| 426 | strerror(-r)); |
| 427 | goto finish; |
| 428 | } |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 429 | |
Chris Austen | 30195fa | 2015-11-13 14:39:19 -0600 | [diff] [blame] | 430 | // Register all the handlers that provider implementation to IPMI commands. |
| 431 | ipmi_register_callback_handlers(HOST_IPMI_LIB_PATH); |
| 432 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 433 | // Watch for BT messages |
vishwa | b9f559a | 2016-01-13 01:53:08 -0600 | [diff] [blame] | 434 | r = sd_bus_add_match(bus, &ipmid_slot, FILTER, handle_ipmi_command, NULL); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 435 | if (r < 0) { |
| 436 | fprintf(stderr, "Failed: sd_bus_add_match: %s : %s\n", strerror(-r), FILTER); |
| 437 | goto finish; |
| 438 | } |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 439 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 440 | |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 441 | for (;;) { |
| 442 | /* Process requests */ |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 443 | r = sd_bus_process(bus, NULL); |
| 444 | if (r < 0) { |
| 445 | fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); |
| 446 | goto finish; |
| 447 | } |
| 448 | if (r > 0) { |
| 449 | continue; |
| 450 | } |
| 451 | |
| 452 | r = sd_bus_wait(bus, (uint64_t) - 1); |
| 453 | if (r < 0) { |
| 454 | fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); |
| 455 | goto finish; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | finish: |
vishwa | b9f559a | 2016-01-13 01:53:08 -0600 | [diff] [blame] | 460 | sd_bus_slot_unref(ipmid_slot); |
Chris Austen | 0ba649e | 2015-10-13 12:28:13 -0500 | [diff] [blame] | 461 | sd_bus_unref(bus); |
| 462 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
| 463 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 464 | } |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 465 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 466 | // Use a lookup table to find the interface name of a specific sensor |
| 467 | // This will be used until an alternative is found. this is the first |
| 468 | // step for mapping IPMI |
| 469 | int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) { |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 470 | |
Joel Stanley | f19539e | 2015-11-25 17:24:05 +1030 | [diff] [blame] | 471 | char *str1; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 472 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 473 | sd_bus_message *reply = NULL, *m=NULL; |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 474 | |
| 475 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 476 | int r; |
| 477 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 478 | r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get"); |
| 479 | if (r < 0) { |
| 480 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 481 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 482 | interface->bus, interface->path, interface->interface); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 483 | goto final; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name); |
| 487 | if (r < 0) { |
| 488 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 489 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 490 | interface->bus, interface->path, interface->interface); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 491 | goto final; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 495 | if (r < 0) { |
| 496 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 497 | goto final; |
| 498 | } |
| 499 | |
| 500 | r = sd_bus_message_read(reply, "v", "s", &str1) ; |
| 501 | if (r < 0) { |
| 502 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 503 | goto final; |
| 504 | } |
| 505 | |
| 506 | strcpy(property_value, str1); |
| 507 | |
| 508 | final: |
| 509 | |
| 510 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 511 | m = sd_bus_message_unref(m); |
| 512 | reply = sd_bus_message_unref(reply); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 513 | |
| 514 | return r; |
| 515 | } |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 516 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 517 | |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 518 | // Use a lookup table to find the interface name of a specific sensor |
| 519 | // This will be used until an alternative is found. this is the first |
| 520 | // step for mapping IPMI |
| 521 | int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { |
| 522 | |
| 523 | const char *busname = "org.openbmc.managers.System"; |
| 524 | const char *objname = "/org/openbmc/managers/System"; |
| 525 | |
| 526 | char *str1, *str2, *str3; |
| 527 | sd_bus_error error = SD_BUS_ERROR_NULL; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 528 | sd_bus_message *reply = NULL; |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 529 | |
| 530 | |
| 531 | int r; |
| 532 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 533 | r = sd_bus_call_method(bus,busname,objname,busname, "getObjectFromByteId", |
| 534 | &error, &reply, "sy", type, num); |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 535 | if (r < 0) { |
| 536 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 537 | goto final; |
| 538 | } |
| 539 | |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 540 | r = sd_bus_message_read(reply, "(sss)", &str1, &str2, &str3); |
| 541 | if (r < 0) { |
| 542 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 543 | goto final; |
| 544 | } |
| 545 | |
| 546 | strncpy(interface->bus, str1, MAX_DBUS_PATH); |
| 547 | strncpy(interface->path, str2, MAX_DBUS_PATH); |
| 548 | strncpy(interface->interface, str3, MAX_DBUS_PATH); |
| 549 | |
| 550 | interface->sensornumber = num; |
| 551 | |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 552 | final: |
| 553 | |
| 554 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 555 | reply = sd_bus_message_unref(reply); |
Chris Austen | b071c70 | 2015-10-15 00:00:09 -0500 | [diff] [blame] | 556 | |
| 557 | return r; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | ///////////////////////////////////////////////////////////////////// |
| 562 | // |
| 563 | // Routines used by ipmi commands wanting to interact on the dbus |
| 564 | // |
| 565 | ///////////////////////////////////////////////////////////////////// |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 566 | int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 567 | |
| 568 | |
| 569 | dbus_interface_t a; |
| 570 | int r; |
| 571 | sd_bus_error error = SD_BUS_ERROR_NULL; |
Joel Stanley | f19539e | 2015-11-25 17:24:05 +1030 | [diff] [blame] | 572 | sd_bus_message *m=NULL; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 573 | |
Chris Austen | 9949731 | 2015-10-22 13:00:16 -0500 | [diff] [blame] | 574 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 575 | number, method, value); |
| 576 | |
| 577 | r = find_openbmc_path("SENSOR", number, &a); |
| 578 | |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 579 | if (r < 0) { |
| 580 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 581 | return 0; |
| 582 | } |
| 583 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 584 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 585 | if (r < 0) { |
| 586 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 587 | goto final; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | r = sd_bus_message_append(m, "v", "s", value); |
| 591 | if (r < 0) { |
| 592 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 593 | goto final; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 597 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 598 | if (r < 0) { |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 599 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 600 | } |
| 601 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 602 | final: |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 603 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 604 | m = sd_bus_message_unref(m); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 605 | |
| 606 | return 0; |
| 607 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 608 | int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { |
| 609 | |
| 610 | |
| 611 | dbus_interface_t a; |
| 612 | int r; |
| 613 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 614 | sd_bus_message *m=NULL; |
| 615 | |
| 616 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 617 | number, method, value); |
| 618 | |
| 619 | r = find_openbmc_path("SENSOR", number, &a); |
| 620 | |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 621 | if (r < 0) { |
| 622 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 623 | return 0; |
| 624 | } |
| 625 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 626 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 627 | if (r < 0) { |
| 628 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 629 | goto final; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 630 | } |
| 631 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 632 | r = sd_bus_message_append(m, "v", "i", value); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 633 | if (r < 0) { |
| 634 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 635 | goto final; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | |
| 639 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 640 | if (r < 0) { |
| 641 | fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); |
| 642 | } |
| 643 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 644 | final: |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 645 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 646 | m = sd_bus_message_unref(m); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 647 | |
| 648 | return 0; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 649 | } |