1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 2 3 #include "compiler.h" 4 #include "libmctp.h" 5 #include "libmctp-serial.h" 6 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 15 static 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) 18 { 19 ssize_t rc; 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); 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 42 mctp_register_bus(mctp, mctp_binding_serial_core(serial), 8); 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