control_legacy.c (fac3689e77d37aca9c85dafabf921a847b1c4e02) control_legacy.c (68a24c9ea5ce11c87fab22a3f4648c7d88c98fee)
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <errno.h>
4#include <stdlib.h>
5
6#include "common.h"
7#include "dbus.h"
8#include "control_dbus.h"

--- 27 unchanged lines hidden (view full) ---

36/*
37 * Command: DBUS Ping
38 * Ping the daemon
39 *
40 * Args: NONE
41 * Resp: NONE
42 */
43static int control_legacy_ping(struct mbox_context *context,
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <errno.h>
4#include <stdlib.h>
5
6#include "common.h"
7#include "dbus.h"
8#include "control_dbus.h"

--- 27 unchanged lines hidden (view full) ---

36/*
37 * Command: DBUS Ping
38 * Ping the daemon
39 *
40 * Args: NONE
41 * Resp: NONE
42 */
43static int control_legacy_ping(struct mbox_context *context,
44 struct mbox_dbus_msg *req,
45 struct mbox_dbus_msg *resp)
44 struct mbox_dbus_msg *req __attribute__((unused)),
45 struct mbox_dbus_msg *resp __attribute__((unused)))
46{
47 return control_ping(context);
48}
49
50/*
51 * Command: DBUS Status
52 * Get the status of the daemon
53 *
54 * Args: NONE
55 * Resp[0]: Status Code
56 */
57static int control_legacy_daemon_state(struct mbox_context *context,
46{
47 return control_ping(context);
48}
49
50/*
51 * Command: DBUS Status
52 * Get the status of the daemon
53 *
54 * Args: NONE
55 * Resp[0]: Status Code
56 */
57static int control_legacy_daemon_state(struct mbox_context *context,
58 struct mbox_dbus_msg *req,
58 struct mbox_dbus_msg *req __attribute__((unused)),
59 struct mbox_dbus_msg *resp)
60{
61 resp->num_args = DAEMON_STATE_NUM_ARGS;
62 resp->args = calloc(resp->num_args, sizeof(*resp->args));
63 resp->args[0] = control_daemon_state(context);
64
65 return 0;
66}
67
68/*
69 * Command: DBUS LPC State
70 * Get the state of the lpc bus mapping (whether it points to memory or flash
71 *
72 * Args: NONE
73 * Resp[0]: LPC Bus State Code
74 */
75static int control_legacy_lpc_state(struct mbox_context *context,
59 struct mbox_dbus_msg *resp)
60{
61 resp->num_args = DAEMON_STATE_NUM_ARGS;
62 resp->args = calloc(resp->num_args, sizeof(*resp->args));
63 resp->args[0] = control_daemon_state(context);
64
65 return 0;
66}
67
68/*
69 * Command: DBUS LPC State
70 * Get the state of the lpc bus mapping (whether it points to memory or flash
71 *
72 * Args: NONE
73 * Resp[0]: LPC Bus State Code
74 */
75static int control_legacy_lpc_state(struct mbox_context *context,
76 struct mbox_dbus_msg *req,
76 struct mbox_dbus_msg *req __attribute__((unused)),
77 struct mbox_dbus_msg *resp)
78{
77 struct mbox_dbus_msg *resp)
78{
79
79 resp->num_args = LPC_STATE_NUM_ARGS;
80 resp->args = calloc(resp->num_args, sizeof(*resp->args));
81 resp->args[0] = control_lpc_state(context);
82
83 return 0;
84}
85
86/*
87 * Command: DBUS Reset
88 * Reset the daemon state, final operation TBA.
89 * For now we just point the lpc mapping back at the flash.
90 *
91 * Args: NONE
92 * Resp: NONE
93 */
94static int control_legacy_reset(struct mbox_context *context,
80 resp->num_args = LPC_STATE_NUM_ARGS;
81 resp->args = calloc(resp->num_args, sizeof(*resp->args));
82 resp->args[0] = control_lpc_state(context);
83
84 return 0;
85}
86
87/*
88 * Command: DBUS Reset
89 * Reset the daemon state, final operation TBA.
90 * For now we just point the lpc mapping back at the flash.
91 *
92 * Args: NONE
93 * Resp: NONE
94 */
95static int control_legacy_reset(struct mbox_context *context,
95 struct mbox_dbus_msg *req,
96 struct mbox_dbus_msg *resp)
96 struct mbox_dbus_msg *req __attribute__((unused)),
97 struct mbox_dbus_msg *resp __attribute__((unused)))
97{
98 int rc;
99
100 rc = control_reset(context);
101
102 /* Map return codes for compatibility */
103 if (rc == -EBUSY) {
104 return -E_DBUS_REJECTED;

--- 7 unchanged lines hidden (view full) ---

112/*
113 * Command: DBUS Kill
114 * Stop the daemon
115 *
116 * Args: NONE
117 * Resp: NONE
118 */
119static int control_legacy_kill(struct mbox_context *context,
98{
99 int rc;
100
101 rc = control_reset(context);
102
103 /* Map return codes for compatibility */
104 if (rc == -EBUSY) {
105 return -E_DBUS_REJECTED;

--- 7 unchanged lines hidden (view full) ---

113/*
114 * Command: DBUS Kill
115 * Stop the daemon
116 *
117 * Args: NONE
118 * Resp: NONE
119 */
120static int control_legacy_kill(struct mbox_context *context,
120 struct mbox_dbus_msg *req,
121 struct mbox_dbus_msg *resp)
121 struct mbox_dbus_msg *req __attribute__((unused)),
122 struct mbox_dbus_msg *resp __attribute__((unused)))
122{
123 return control_kill(context);
124}
125
126/*
127 * Command: DBUS Flash Modified
128 * Used to notify the daemon that the flash has been modified out from under
129 * it - We need to reset all out windows to ensure flash will be reloaded
130 * when a new window is opened.
131 * Note: We don't flush any previously opened windows
132 *
133 * Args: NONE
134 * Resp: NONE
135 */
136static int control_legacy_modified(struct mbox_context *context,
123{
124 return control_kill(context);
125}
126
127/*
128 * Command: DBUS Flash Modified
129 * Used to notify the daemon that the flash has been modified out from under
130 * it - We need to reset all out windows to ensure flash will be reloaded
131 * when a new window is opened.
132 * Note: We don't flush any previously opened windows
133 *
134 * Args: NONE
135 * Resp: NONE
136 */
137static int control_legacy_modified(struct mbox_context *context,
137 struct mbox_dbus_msg *req,
138 struct mbox_dbus_msg *resp)
138 struct mbox_dbus_msg *req __attribute__((unused)),
139 struct mbox_dbus_msg *resp __attribute__((unused)))
139{
140 return control_modified(context);
141}
142
143/*
144 * Command: DBUS Suspend
145 * Suspend the daemon to inhibit it from performing flash accesses.
146 * This is used to synchronise access to the flash between the daemon and
147 * directly from the BMC.
148 *
149 * Args: NONE
150 * Resp: NONE
151 */
152static int control_legacy_suspend(struct mbox_context *context,
140{
141 return control_modified(context);
142}
143
144/*
145 * Command: DBUS Suspend
146 * Suspend the daemon to inhibit it from performing flash accesses.
147 * This is used to synchronise access to the flash between the daemon and
148 * directly from the BMC.
149 *
150 * Args: NONE
151 * Resp: NONE
152 */
153static int control_legacy_suspend(struct mbox_context *context,
153 struct mbox_dbus_msg *req,
154 struct mbox_dbus_msg *resp)
154 struct mbox_dbus_msg *req __attribute__((unused)),
155 struct mbox_dbus_msg *resp __attribute__((unused)))
155{
156 int rc;
157
158 rc = control_suspend(context);
159 if (rc < 0) {
160 /* Map return codes for compatibility */
161 return -E_DBUS_HARDWARE;
162 }

--- 5 unchanged lines hidden (view full) ---

168 * Command: DBUS Resume
169 * Resume the daemon to let it perform flash accesses again.
170 *
171 * Args[0]: Flash Modified (0 - no | 1 - yes)
172 * Resp: NONE
173 */
174static int control_legacy_resume(struct mbox_context *context,
175 struct mbox_dbus_msg *req,
156{
157 int rc;
158
159 rc = control_suspend(context);
160 if (rc < 0) {
161 /* Map return codes for compatibility */
162 return -E_DBUS_HARDWARE;
163 }

--- 5 unchanged lines hidden (view full) ---

169 * Command: DBUS Resume
170 * Resume the daemon to let it perform flash accesses again.
171 *
172 * Args[0]: Flash Modified (0 - no | 1 - yes)
173 * Resp: NONE
174 */
175static int control_legacy_resume(struct mbox_context *context,
176 struct mbox_dbus_msg *req,
176 struct mbox_dbus_msg *resp)
177 struct mbox_dbus_msg *resp __attribute__((unused)))
177{
178 int rc;
179
180 if (req->num_args != 1) {
181 return -E_DBUS_INVAL;
182 }
183
184 rc = control_resume(context, req->args[0] == RESUME_FLASH_MODIFIED);

--- 15 unchanged lines hidden (view full) ---

200 control_legacy_suspend,
201 control_legacy_resume,
202 control_legacy_modified,
203 control_legacy_kill,
204 control_legacy_lpc_state
205};
206
207static int method_cmd(sd_bus_message *m, void *userdata,
178{
179 int rc;
180
181 if (req->num_args != 1) {
182 return -E_DBUS_INVAL;
183 }
184
185 rc = control_resume(context, req->args[0] == RESUME_FLASH_MODIFIED);

--- 15 unchanged lines hidden (view full) ---

201 control_legacy_suspend,
202 control_legacy_resume,
203 control_legacy_modified,
204 control_legacy_kill,
205 control_legacy_lpc_state
206};
207
208static int method_cmd(sd_bus_message *m, void *userdata,
208 sd_bus_error *ret_error)
209 sd_bus_error *ret_error __attribute__((unused)))
209{
210 struct mbox_dbus_msg req = { 0 }, resp = { 0 };
211 struct mbox_context *context;
212 sd_bus_message *n;
210{
211 struct mbox_dbus_msg req = { 0 }, resp = { 0 };
212 struct mbox_context *context;
213 sd_bus_message *n;
213 int rc, i;
214 int rc;
215 size_t i;
214
215 context = (struct mbox_context *) userdata;
216 if (!context) {
217 MSG_ERR("DBUS Internal Error\n");
218 rc = -E_DBUS_INTERNAL;
219 goto out;
220 }
221

--- 11 unchanged lines hidden (view full) ---

233 &req.num_args);
234 if (rc < 0) {
235 MSG_ERR("DBUS error reading message: %s\n", strerror(-rc));
236 rc = -E_DBUS_INTERNAL;
237 goto out;
238 }
239 MSG_DBG("DBUS num_args: %u\n", (unsigned) req.num_args);
240 for (i = 0; i < req.num_args; i++) {
216
217 context = (struct mbox_context *) userdata;
218 if (!context) {
219 MSG_ERR("DBUS Internal Error\n");
220 rc = -E_DBUS_INTERNAL;
221 goto out;
222 }
223

--- 11 unchanged lines hidden (view full) ---

235 &req.num_args);
236 if (rc < 0) {
237 MSG_ERR("DBUS error reading message: %s\n", strerror(-rc));
238 rc = -E_DBUS_INTERNAL;
239 goto out;
240 }
241 MSG_DBG("DBUS num_args: %u\n", (unsigned) req.num_args);
242 for (i = 0; i < req.num_args; i++) {
241 MSG_DBG("DBUS arg[%d]: %u\n", i, req.args[i]);
243 MSG_DBG("DBUS arg[%zd]: %u\n", i, req.args[i]);
242 }
243
244 /* Handle the command */
245 if (req.cmd >= NUM_DBUS_CMDS) {
246 rc = -E_DBUS_INVAL;
247 MSG_ERR("Received unknown dbus cmd: %d\n", req.cmd);
248 } else {
249 rc = dbus_handlers[req.cmd](context, &req, &resp);

--- 19 unchanged lines hidden (view full) ---

269 if (rc < 0) {
270 MSG_ERR("sd_bus_message_append_array failed: %d\n", rc);
271 goto cleanup;
272 }
273
274 MSG_DBG("DBUS response: %u\n", resp.cmd);
275 MSG_DBG("DBUS num_args: %u\n", (unsigned) resp.num_args);
276 for (i = 0; i < resp.num_args; i++) {
244 }
245
246 /* Handle the command */
247 if (req.cmd >= NUM_DBUS_CMDS) {
248 rc = -E_DBUS_INVAL;
249 MSG_ERR("Received unknown dbus cmd: %d\n", req.cmd);
250 } else {
251 rc = dbus_handlers[req.cmd](context, &req, &resp);

--- 19 unchanged lines hidden (view full) ---

271 if (rc < 0) {
272 MSG_ERR("sd_bus_message_append_array failed: %d\n", rc);
273 goto cleanup;
274 }
275
276 MSG_DBG("DBUS response: %u\n", resp.cmd);
277 MSG_DBG("DBUS num_args: %u\n", (unsigned) resp.num_args);
278 for (i = 0; i < resp.num_args; i++) {
277 MSG_DBG("DBUS arg[%d]: %u\n", i, resp.args[i]);
279 MSG_DBG("DBUS arg[%zd]: %u\n", i, resp.args[i]);
278 }
279
280 rc = sd_bus_send(NULL, n, NULL); /* Send response */
281 sd_bus_message_unref(n);
282 if (rc < 0)
283 MSG_ERR("sd_bus_send failed: %d\n", rc);
284
285cleanup:

--- 33 unchanged lines hidden ---
280 }
281
282 rc = sd_bus_send(NULL, n, NULL); /* Send response */
283 sd_bus_message_unref(n);
284 if (rc < 0)
285 MSG_ERR("sd_bus_send failed: %d\n", rc);
286
287cleanup:

--- 33 unchanged lines hidden ---