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