diff options
author | Christian Pointner <equinox@spreadspace.org> | 2018-11-29 00:03:23 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2018-11-29 00:03:23 +0100 |
commit | 21d747167d1091985438f6a2c954cdc895031c07 (patch) | |
tree | 1b16c2333c097cd639c85bc1999498bfe1ff5622 /usb-lora-crypto | |
parent | added decryption example (diff) |
radiohead with crypto support
Diffstat (limited to 'usb-lora-crypto')
-rw-r--r-- | usb-lora-crypto/Makefile | 52 | ||||
-rw-r--r-- | usb-lora-crypto/usb-lora-crypto.cpp | 118 |
2 files changed, 170 insertions, 0 deletions
diff --git a/usb-lora-crypto/Makefile b/usb-lora-crypto/Makefile new file mode 100644 index 0000000..0b61c94 --- /dev/null +++ b/usb-lora-crypto/Makefile @@ -0,0 +1,52 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org> +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. +## + +NAME := usb-lora-crypto +BOARD_TYPE := elecrow32u4lora +CXX_OBJ := $(NAME).o +LIBS := util led lufa-descriptor-usbserial usbio +EXTERNAL_LIBS := lufa radiohead rweather-crypto +SPREADAVR_PATH := .. + +LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-151115 +LUFA_OPTS = -D USB_DEVICE_ONLY +LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 +LUFA_OPTS += -D ORDERED_EP_CONFIG +LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 +LUFA_OPTS += -D USE_FLASH_DESCRIPTORS +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT + +LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" +LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-lora-crypto example\"" + +LUFA_COMPONENTS := USB USBCLASS + + +RADIOHEAD_PATH := $(SPREADAVR_PATH)/contrib/RadioHead + +RADIOHEAD_DRIVER := RF95 + +RWEATHER_CRYPTO_PATH := $(SPREADAVR_PATH)/contrib/rweather-crypto + +include $(SPREADAVR_PATH)/include.mk diff --git a/usb-lora-crypto/usb-lora-crypto.cpp b/usb-lora-crypto/usb-lora-crypto.cpp new file mode 100644 index 0000000..3af1dcb --- /dev/null +++ b/usb-lora-crypto/usb-lora-crypto.cpp @@ -0,0 +1,118 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <avr/io.h> +#include <avr/wdt.h> +#include <avr/interrupt.h> +#include <avr/power.h> +#include <stdio.h> + +#include "util.h" +#include "led.h" +#include "usbio.h" + +#include "RadioHead.h" +#include "RH_RF95.h" +#include <Crypto.h> +#include <ChaChaPoly.h> +#include "RHAEADDriver.h" + +ChaChaPoly cipher; +RH_RF95 lora; +RHAEADDriver aead(lora, cipher); + +void recv_aead_msg() +{ + uint8_t buf[RH_RF95_MAX_MESSAGE_LEN+1]; + uint8_t len = sizeof(buf)-1; + + led2_on(); + if(!aead.recv(buf, &len)) { + printf("aead.recv(): failed\r\n"); + led2_off(); + return; + } + buf[len] = 0; + + printf("aead.recv() got message: RSSI = %d, data = ", aead.lastRssi()); + for(uint8_t i = 0; i < len; ++i) printf("%s0x%02X", (i==0) ? "" : " ", buf[i]); + printf("\r\n"); + // printf("aead.recv() got message: RSSI = %d, data = %s\r\n", aead.lastRssi(), buf); + led2_off(); +} + +void send_aead_msg() +{ + uint8_t data[] = "spreadspace.org/avr-utils usb-aead test using radiohead library"; + printf("aead: sending message with %d bytes\r\n", sizeof(data)); + + led_on(); + if(!aead.send(data, sizeof(data))) { + printf("aead.send(): failed\r\n"); + led_off(); + return; + } + aead.waitPacketSent(); + printf("aead.send(): success\r\n"); + led_off(); +} + +void handle_cmd(uint8_t cmd) +{ + switch(cmd) { + case 's': send_aead_msg(); break; + default: printf("error\r\n"); return; + } +} + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); + usbio_init(); + arduino_init(); + sei(); + + lora.init(); + lora.setFrequency(868.0); + aead.init(); + + for(;;) { + if(aead.available()) { + recv_aead_msg(); + } + + int16_t BytesReceived = usbio_bytes_received(); + while(BytesReceived > 0) { + int ReceivedByte = fgetc(stdin); + if(ReceivedByte != EOF) { + handle_cmd(ReceivedByte); + } + BytesReceived--; + } + + usbio_task(); + } +} |