cli.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __CLI_H
  2. #define __CLI_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "FreeRTOS.h"
  6. #include "fr_timers.h"
  7. #include "settings_api.h"
  8. /* Dimensions the buffer into which input characters are placed. */
  9. #define cmdMAX_INPUT_SIZE 144
  10. #define MAX_SESSIONS 2
  11. #define array_len(x) (sizeof(x)/sizeof(x[0]))
  12. typedef enum{
  13. CLI_AUTH = 0,
  14. CLI_AUTH_PASSW,
  15. CLI_CMD,
  16. CLI_CHANGE_PWD,
  17. CLI_CHANGE_PWD_ACK
  18. } input_state_t;
  19. typedef enum {
  20. STATE_UNUSED,
  21. STATE_NORMAL,
  22. STATE_CLOSE,
  23. } conn_state_t;
  24. /**
  25. * A cli connection structure.
  26. */
  27. typedef struct {
  28. TimerHandle_t RepeatSensorInfoTimer;
  29. conn_state_t state;
  30. char buf[cmdMAX_INPUT_SIZE];
  31. uint_fast8_t bufptr;
  32. char prev_cmd[cmdMAX_INPUT_SIZE];
  33. unsigned char optdata[cmdMAX_INPUT_SIZE];
  34. uint8_t optlen;
  35. input_state_t input_state;
  36. user_level_t user_id;
  37. char login[MAX_WEB_LOGIN_LEN];
  38. uint8_t login_err; // the number of failed password entry attempts
  39. bool flag_telnet_ip_option; // wtf is this
  40. void (*send)(intptr_t fd, const char *str, unsigned len);
  41. intptr_t num_connect; // fd
  42. } cli_state_t;
  43. extern cli_state_t cli_states[MAX_SESSIONS];
  44. void cli_init(void);
  45. void cli_getchar(cli_state_t *s, char incoming_char);
  46. cli_state_t *alloc_state(void);
  47. void free_state(cli_state_t *state);
  48. void cli_hello(cli_state_t *cli_state);
  49. user_level_t cli_auth_user(char *user, char *password);
  50. void cli_close_connections(void);
  51. #endif