cli.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_IAC,
  23. STATE_OPT,
  24. STATE_SB,
  25. STATE_OPTDAT,
  26. STATE_SE,
  27. STATE_CLOSE,
  28. } conn_state_t;
  29. /**
  30. * A cli connection structure.
  31. */
  32. typedef struct {
  33. TimerHandle_t RepeatSensorInfoTimer;
  34. conn_state_t state;
  35. char buf[cmdMAX_INPUT_SIZE];
  36. uint_fast8_t bufptr;
  37. char prev_cmd[cmdMAX_INPUT_SIZE];
  38. unsigned char optdata[cmdMAX_INPUT_SIZE];
  39. uint8_t optlen;
  40. input_state_t input_state;
  41. user_level_t user_id;
  42. char login[MAX_WEB_LOGIN_LEN];
  43. uint8_t login_err; // the number of failed password entry attempts
  44. bool flag_telnet_ip_option; // wtf is this
  45. void (*send)(intptr_t fd, const char *str, unsigned len);
  46. intptr_t num_connect; // fd
  47. } cli_state_t;
  48. extern cli_state_t cli_states[MAX_SESSIONS];
  49. void cli_init(void);
  50. void cli_getchar(cli_state_t *s, char incoming_char);
  51. cli_state_t *alloc_state(void);
  52. void free_state(cli_state_t *state);
  53. void cli_hello(cli_state_t *cli_state);
  54. user_level_t cli_auth_user(char *user, char *password);
  55. void cli_close_connections(void);
  56. #endif