Jeremy Kerr | 3d36ee2 | 2019-05-30 11:15:37 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Jeremy Kerr | 4cdc200 | 2019-02-07 16:49:12 +0800 | [diff] [blame] | 2 | |
Andrew Jeffery | 5ab7825 | 2022-02-17 21:04:59 +1030 | [diff] [blame] | 3 | #include "compiler.h" |
| 4 | #include "libmctp.h" |
| 5 | #include "libmctp-serial.h" |
| 6 | |
Jeremy Kerr | 4cdc200 | 2019-02-07 16:49:12 +0800 | [diff] [blame] | 7 | #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 | |
Sumanth Bhat | f39c385 | 2022-01-10 17:04:10 +0530 | [diff] [blame] | 15 | static void |
| 16 | rx_message(uint8_t eid __unused, bool tag_owner __unused, |
| 17 | uint8_t msg_tag __unused, void *data __unused, void *msg, size_t len) |
Jeremy Kerr | 4cdc200 | 2019-02-07 16:49:12 +0800 | [diff] [blame] | 18 | { |
Andrew Jeffery | f967c70 | 2022-02-17 17:41:35 +1030 | [diff] [blame] | 19 | ssize_t rc; |
Andrew Jeffery | f967c70 | 2022-02-17 17:41:35 +1030 | [diff] [blame] | 20 | |
| 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 Kerr | 4cdc200 | 2019-02-07 16:49:12 +0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | int 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 Bishop | e4d8456 | 2021-11-30 14:04:10 -0500 | [diff] [blame] | 42 | mctp_register_bus(mctp, mctp_binding_serial_core(serial), 8); |
Jeremy Kerr | 4cdc200 | 2019-02-07 16:49:12 +0800 | [diff] [blame] | 43 | |
| 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; |
| 53 | |
| 54 | } |