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.
 
 
 
 
 
 

86 lines
3.3 KiB

  1. # Copyright 2022 John-Mark Gurney.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  13. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  16. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. # SUCH DAMAGE.
  23. #
  24. PROGS = rs485gw rs485hid
  25. SRCS.rs485gw = rs485gw.c
  26. SRCS.rs485gw+= $(SRCS.USB_CDC)
  27. SRCS.rs485gw+= $(SRCS.USB)
  28. SRCS.rs485hid = rs485hid.c
  29. SRCS.rs485hid+= $(SRCS.USB_HID)
  30. SRCS.rs485hid+= $(SRCS.USB)
  31. SRCS.rs485hid+= $(STROBE_SRCS)
  32. SRCS.rs485hid+= comms.c
  33. SRCS.rs485hid+= memdebug.c
  34. SRCS.rs485hid+= strobe_pki.c
  35. CFLAGS.rs485hid+= -DEXTERNAL_GET_DESCRIPTOR=1
  36. CFLAGS.rs485hid+= -I$(.OBJDIR) # for public_key.h
  37. SRCS.rs485hid+= usb_hid_base.c
  38. .if empty(HID_PRIV_KEY) && exists($(.CURDIR)/.hid_priv_key)
  39. HID_PRIV_KEY!= cat $(.CURDIR)/.hid_priv_key
  40. .endif
  41. .PHONY: hid_priv_key
  42. hid_priv_key:
  43. @LANG=C tr -c -d a-f0-9 < /dev/urandom | dd bs=1 of=$(.CURDIR)/.hid_priv_key count=64 2>/dev/null
  44. @echo 'Key created and put into .hid_priv_key.'
  45. # make this a phony target so it's always run
  46. # dependancies will only be made when it's updated
  47. .PHONY: $(.OBJDIR)/public_key.h
  48. $(.OBJDIR)/public_key.h:
  49. @if [ "$(HID_PRIV_KEY)" = "" ]; then echo 'Must provide HID_PRIV_KEY make variable or have a non-empty file ".hid_priv_key". This can be created by the command "$(MAKE) hid_priv_key".'; false; fi
  50. @echo 'static const uint8_t pubkey[] = {' $$(python3 -c 'import sys; import codecs; from syote_comms import X25519; print(", ".join(hex(x) for x in X25519.frombytes(codecs.decode(sys.argv[1], "hex")).getpub()))' $(HID_PRIV_KEY) ) "};" > public_key.h.tmp
  51. @echo 'static_assert(sizeof pubkey == 32);' >> public_key.h.tmp
  52. if [ "$$(cat public_key.h.tmp)" = "static uint8_t pubkey[] = { };" -o "$$(cat public_key.h.tmp)" = "" ]; then rm -f "$@"; false; fi
  53. (cmp public_key.h.tmp public_key.h >/dev/null 2>&1 && rm public_key.h.tmp) || mv public_key.h.tmp public_key.h
  54. strobe_pki.o: $(.OBJDIR)/public_key.h
  55. usb_hid_base.c: usb_hid.py
  56. PYTHONPATH=$(.CURDIR) python $(STM32)/usb/usb_gen.py $(.ALLSRC:[1]:T:R)
  57. .PATH: $(.CURDIR)/..
  58. CFLAGS += -g
  59. WITH_RS485FRAME = yes
  60. WITH_STM32F103 = yes
  61. WITH_USB_CDC = yes
  62. WITH_USB_HID = yes
  63. .include <../mk/boards.mk>
  64. EXTRA_DEPENDS+= $(STM32)/usb/usb_gen.py
  65. .include <../mk/mu.progs.mk>
  66. usb_hid_base.c: $(STM32)/usb/usb_gen.py