blob: 44b00b1aff89374a93f194564562670a56665903 [file] [log] [blame]
Jeremy Kerr3d36ee22019-05-30 11:15:37 +08001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Jeremy Kerr4cdc2002019-02-07 16:49:12 +08002
Andrew Jeffery5ab78252022-02-17 21:04:59 +10303#include "compiler.h"
4#include "libmctp.h"
5#include "libmctp-serial.h"
6
Jeremy Kerr4cdc2002019-02-07 16:49:12 +08007#include <assert.h>
8#include <err.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <sys/poll.h>
13#include <sys/socket.h>
14
Andrew Jeffery2c69ab32022-09-30 14:19:02 +093015static void rx_message(uint8_t eid __unused, bool tag_owner __unused,
16 uint8_t msg_tag __unused, void *data __unused, void *msg,
17 size_t len)
Jeremy Kerr4cdc2002019-02-07 16:49:12 +080018{
Andrew Jefferyf967c702022-02-17 17:41:35 +103019 ssize_t rc;
Andrew Jefferyf967c702022-02-17 17:41:35 +103020
21 rc = write(STDOUT_FILENO, msg, len);
22 if (rc < 0)
23 warn("Write failed");
24 else if ((size_t)rc < len)
25 warnx("Short write of length %zd, requested %zd", rc, len);
Jeremy Kerr4cdc2002019-02-07 16:49:12 +080026}
27
28int main(void)
29{
30 struct mctp_binding_serial *serial;
31 struct mctp *mctp;
32 int rc;
33
34 mctp = mctp_init();
35 assert(mctp);
36
37 serial = mctp_serial_init();
38 assert(serial);
39
40 mctp_serial_open_fd(serial, STDIN_FILENO);
41
Brad Bishope4d84562021-11-30 14:04:10 -050042 mctp_register_bus(mctp, mctp_binding_serial_core(serial), 8);
Jeremy Kerr4cdc2002019-02-07 16:49:12 +080043
44 mctp_set_rx_all(mctp, rx_message, NULL);
45
46 for (;;) {
47 rc = mctp_serial_read(serial);
48 if (rc)
49 break;
50 }
51
52 return EXIT_SUCCESS;
Jeremy Kerr4cdc2002019-02-07 16:49:12 +080053}