cli.h 1.5 KB

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