You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tcp_comm.h 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2022 Brian Starkey <stark3y@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef __TCP_COMM_H__
  7. #define __TCP_COMM_H__
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #define TCP_COMM_MAX_DATA_LEN 1024
  11. #define TCP_COMM_RSP_OK (('O' << 0) | ('K' << 8) | ('O' << 16) | ('K' << 24))
  12. #define TCP_COMM_RSP_ERR (('E' << 0) | ('R' << 8) | ('R' << 16) | ('!' << 24))
  13. struct comm_command {
  14. uint32_t opcode;
  15. uint32_t nargs;
  16. uint32_t resp_nargs;
  17. uint32_t (*size)(uint32_t *args_in, uint32_t *data_len_out, uint32_t *resp_data_len_out);
  18. uint32_t (*handle)(uint32_t *args_in, uint8_t *data_in, uint32_t *resp_args_out, uint8_t *resp_data_out);
  19. };
  20. struct tcp_comm_ctx;
  21. err_t tcp_comm_listen(struct tcp_comm_ctx *ctx, uint16_t port);
  22. err_t tcp_comm_server_close(struct tcp_comm_ctx *ctx);
  23. bool tcp_comm_server_done(struct tcp_comm_ctx *ctx);
  24. struct tcp_comm_ctx *tcp_comm_new(const struct comm_command *const *cmds,
  25. unsigned int n_cmds, uint32_t sync_opcode);
  26. void tcp_comm_delete(struct tcp_comm_ctx *ctx);
  27. #endif /* __TCP_COMM_H__ */