Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

40 lines
866 B

  1. #include <sys/types.h>
  2. #include <stdint.h>
  3. #include <strobe.h>
  4. #define COMMS_MAXMSG 64
  5. struct pktbuf {
  6. uint8_t *pkt;
  7. uint16_t pktlen;
  8. };
  9. /* first arg is input buffer, second arg is what will be sent as reply */
  10. typedef void (*process_msgfunc_t)(struct pktbuf, struct pktbuf *);
  11. enum comm_state {
  12. COMMS_WAIT_REQUEST = 1,
  13. COMMS_WAIT_CONFIRM,
  14. COMMS_PROCESS_MSGS,
  15. };
  16. struct comms_state {
  17. strobe_s cs_state;
  18. enum comm_state cs_comm_state;
  19. strobe_s cs_start; /* special starting state cache */
  20. process_msgfunc_t cs_procmsg;
  21. struct pktbuf cs_prevmsg;
  22. struct pktbuf cs_prevmsgresp;
  23. uint8_t cs_prevmsgbuf[COMMS_MAXMSG];
  24. uint8_t cs_prevmsgrespbuf[COMMS_MAXMSG];
  25. };
  26. size_t _strobe_state_size();
  27. void comms_init(struct comms_state *, process_msgfunc_t, struct pktbuf *);
  28. void comms_process(struct comms_state *, struct pktbuf, struct pktbuf *);