1*5f657a7fSCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause 2*5f657a7fSCristian Dumitrescu * Copyright(c) 2020 Intel Corporation 3*5f657a7fSCristian Dumitrescu */ 4*5f657a7fSCristian Dumitrescu 5*5f657a7fSCristian Dumitrescu #ifndef __INCLUDE_CONN_H__ 6*5f657a7fSCristian Dumitrescu #define __INCLUDE_CONN_H__ 7*5f657a7fSCristian Dumitrescu 8*5f657a7fSCristian Dumitrescu #include <stdint.h> 9*5f657a7fSCristian Dumitrescu 10*5f657a7fSCristian Dumitrescu struct conn; 11*5f657a7fSCristian Dumitrescu 12*5f657a7fSCristian Dumitrescu #ifndef CONN_WELCOME_LEN_MAX 13*5f657a7fSCristian Dumitrescu #define CONN_WELCOME_LEN_MAX 1024 14*5f657a7fSCristian Dumitrescu #endif 15*5f657a7fSCristian Dumitrescu 16*5f657a7fSCristian Dumitrescu #ifndef CONN_PROMPT_LEN_MAX 17*5f657a7fSCristian Dumitrescu #define CONN_PROMPT_LEN_MAX 16 18*5f657a7fSCristian Dumitrescu #endif 19*5f657a7fSCristian Dumitrescu 20*5f657a7fSCristian Dumitrescu typedef void 21*5f657a7fSCristian Dumitrescu (*conn_msg_handle_t)(char *msg_in, 22*5f657a7fSCristian Dumitrescu char *msg_out, 23*5f657a7fSCristian Dumitrescu size_t msg_out_len_max, 24*5f657a7fSCristian Dumitrescu void *arg); 25*5f657a7fSCristian Dumitrescu 26*5f657a7fSCristian Dumitrescu struct conn_params { 27*5f657a7fSCristian Dumitrescu const char *welcome; 28*5f657a7fSCristian Dumitrescu const char *prompt; 29*5f657a7fSCristian Dumitrescu const char *addr; 30*5f657a7fSCristian Dumitrescu uint16_t port; 31*5f657a7fSCristian Dumitrescu size_t buf_size; 32*5f657a7fSCristian Dumitrescu size_t msg_in_len_max; 33*5f657a7fSCristian Dumitrescu size_t msg_out_len_max; 34*5f657a7fSCristian Dumitrescu conn_msg_handle_t msg_handle; 35*5f657a7fSCristian Dumitrescu void *msg_handle_arg; 36*5f657a7fSCristian Dumitrescu }; 37*5f657a7fSCristian Dumitrescu 38*5f657a7fSCristian Dumitrescu struct conn * 39*5f657a7fSCristian Dumitrescu conn_init(struct conn_params *p); 40*5f657a7fSCristian Dumitrescu 41*5f657a7fSCristian Dumitrescu void 42*5f657a7fSCristian Dumitrescu conn_free(struct conn *conn); 43*5f657a7fSCristian Dumitrescu 44*5f657a7fSCristian Dumitrescu int 45*5f657a7fSCristian Dumitrescu conn_poll_for_conn(struct conn *conn); 46*5f657a7fSCristian Dumitrescu 47*5f657a7fSCristian Dumitrescu int 48*5f657a7fSCristian Dumitrescu conn_poll_for_msg(struct conn *conn); 49*5f657a7fSCristian Dumitrescu 50*5f657a7fSCristian Dumitrescu #endif 51