Implemented LoRa promiscuous mode

This commit is contained in:
Mark Qvist 2018-06-27 11:42:48 +02:00
parent 4f9cfee7c2
commit d493e5e311
3 changed files with 157 additions and 71 deletions

View File

@ -4,7 +4,7 @@
#define CONFIG_H #define CONFIG_H
#define MAJ_VERS 0x01 #define MAJ_VERS 0x01
#define MIN_VERS 0x04 #define MIN_VERS 0x05
#define MCU_328P 0x90 #define MCU_328P 0x90
#define MCU_1284P 0x91 #define MCU_1284P 0x91
@ -77,6 +77,8 @@
bool radio_locked = true; bool radio_locked = true;
bool radio_online = false; bool radio_online = false;
bool hw_ready = false; bool hw_ready = false;
bool promisc = false;
uint8_t op_mode = MODE_HOST; uint8_t op_mode = MODE_HOST;
uint8_t model = 0x00; uint8_t model = 0x00;
uint8_t hwrev = 0x00; uint8_t hwrev = 0x00;

View File

@ -89,6 +89,12 @@ void update_radio_lock() {
} }
void receiveCallback(int packet_size) { void receiveCallback(int packet_size) {
if (!promisc) {
// The standard operating mode allows large
// packets with a payload up to 500 bytes,
// by combining two raw LoRa packets.
// We read the 1-byte header and extract
// packet sequence number and split flags
uint8_t header = LoRa.read(); packet_size--; uint8_t header = LoRa.read(); packet_size--;
uint8_t sequence = packetSequence(header); uint8_t sequence = packetSequence(header);
bool ready = false; bool ready = false;
@ -142,6 +148,31 @@ void receiveCallback(int packet_size) {
Serial.write(CMD_STAT_RSSI); Serial.write(CMD_STAT_RSSI);
Serial.write((uint8_t)(last_rssi-rssi_offset)); Serial.write((uint8_t)(last_rssi-rssi_offset));
// And then write the entire packet
Serial.write(FEND);
Serial.write(CMD_DATA);
for (int i = 0; i < read_len; i++) {
uint8_t byte = pbuf[i];
if (byte == FEND) { Serial.write(FESC); byte = TFEND; }
if (byte == FESC) { Serial.write(FESC); byte = TFESC; }
Serial.write(byte);
}
Serial.write(FEND);
read_len = 0;
}
} else {
// In promiscuous mode, raw packets are
// output directly over to the host
read_len = 0;
last_rssi = LoRa.packetRssi();
getPacketData(packet_size);
// We first signal the RSSI of the
// recieved packet to the host.
Serial.write(FEND);
Serial.write(CMD_STAT_RSSI);
Serial.write((uint8_t)(last_rssi-rssi_offset));
// And then write the entire packet // And then write the entire packet
Serial.write(FEND); Serial.write(FEND);
Serial.write(CMD_DATA); Serial.write(CMD_DATA);
@ -216,6 +247,7 @@ void processQueue() {
void transmit(size_t size) { void transmit(size_t size) {
if (radio_online) { if (radio_online) {
if (!promisc) {
led_tx_on(); led_tx_on();
size_t written = 0; size_t written = 0;
uint8_t header = random(256) & 0xF0; uint8_t header = random(256) & 0xF0;
@ -248,7 +280,33 @@ void transmit(size_t size) {
led_tx_off(); led_tx_off();
LoRa.receive(); LoRa.receive();
} else {
// In promiscuous mode, we only send out
// plain raw LoRa packets with a maximum
// payload of 255 bytes
led_tx_on();
size_t written = 0;
// Cap packets at 255 bytes
if (size > SINGLE_MTU) {
size = SINGLE_MTU;
}
LoRa.beginPacket();
for (size_t i; i < size; i++) {
#if QUEUE_SIZE > 0
LoRa.write(tbuf[i]);
#else
LoRa.write(sbuf[i]);
#endif
written++;
}
LoRa.endPacket();
led_tx_off();
LoRa.receive();
}
} else { } else {
kiss_indicate_error(ERROR_TXFAILED); kiss_indicate_error(ERROR_TXFAILED);
led_indicate_error(5); led_indicate_error(5);
@ -400,6 +458,13 @@ void serialCallback(uint8_t sbyte) {
if (sbyte == DETECT_REQ) { if (sbyte == DETECT_REQ) {
kiss_indicate_detect(); kiss_indicate_detect();
} }
} else if (command == CMD_PROMISC) {
if (sbyte == 0x01) {
promisc_enable();
} else if (sbyte == 0x00) {
promisc_disable();
}
kiss_indicate_promisc();
} else if (command == CMD_UNLOCK_ROM) { } else if (command == CMD_UNLOCK_ROM) {
if (sbyte == ROM_UNLOCK_BYTE) { if (sbyte == ROM_UNLOCK_BYTE) {
unlock_rom(); unlock_rom();

View File

@ -199,6 +199,17 @@ void kiss_indicate_ready() {
Serial.write(FEND); Serial.write(FEND);
} }
void kiss_indicate_promisc() {
Serial.write(FEND);
Serial.write(CMD_PROMISC);
if (promisc) {
Serial.write(0x01);
} else {
Serial.write(0x00);
}
Serial.write(FEND);
}
void kiss_indicate_detect() { void kiss_indicate_detect() {
Serial.write(FEND); Serial.write(FEND);
Serial.write(CMD_DETECT); Serial.write(CMD_DETECT);
@ -278,6 +289,14 @@ uint8_t getRandom() {
} }
} }
void promisc_enable() {
promisc = true;
}
void promisc_disable() {
promisc = false;
}
bool eeprom_info_locked() { bool eeprom_info_locked() {
uint8_t lock_byte = EEPROM.read(eeprom_addr(ADDR_INFO_LOCK)); uint8_t lock_byte = EEPROM.read(eeprom_addr(ADDR_INFO_LOCK));
if (lock_byte == INFO_LOCK_BYTE) { if (lock_byte == INFO_LOCK_BYTE) {