Commit c0e772b5 authored by Guillaume Gonnet's avatar Guillaume Gonnet
Browse files

Fix OTAA replay and some other small bugs.

parent 02280194
......@@ -4,8 +4,8 @@ This file decodes a JOIN message sent on port 10.
Usage: node decode-join.js <app key> <payload>
Example: node decode-join.js \
4b20ef23b1c3a9393f034f6527ca71f2 \
1C386337ccbbaae7cd2c010000184F84E85684B85E84886684586E8400AB7800
08ACA94CA5FD3EF1119D7B735EE73D5A \
1c0100002b00c0d7af00fc0001184f84e85684b85e84886684586e840086a4ee
The format of the payload is the following:
<join size> <join accept + cf list> <padding> <dev nonce> <zero>
......@@ -38,7 +38,7 @@ if (appkey.length != 16) {
}
if (payload.length != 32) {
console.error("Input payload must have at least 32 bytes.");
console.error("Input payload must have exaclty 32 bytes.");
process.exit(1);
}
......
......@@ -22,11 +22,12 @@ static void send_message(void)
{
lorariot_mcps_t mcps = LORARIOT_UNCONFIRMED(DR_0);
mcps.power = 19;
mcps.buffer = (uint8_t *)"Ballon!";
mcps.len = 7;
puts("Sending message ...");
pvd_send(&pvd_orange_bm, &mcps);
pvd_send(&pvd_orange_cmd, &mcps);
puts("Message sent!");
}
......@@ -44,13 +45,14 @@ int main(void)
#if RESET_ON_START
// If enable, reset all providers when the application starts.
pvd_reset_all();
// pvd_reset_all();
#endif
xtimer_sleep(10);
// xtimer_sleep(10);
while (true) {
send_message();
xtimer_sleep(30);
return 0;
xtimer_sleep(90);
}
}
......@@ -24,10 +24,9 @@ void pvd_otaa_enable(provider_t *pvd)
// Replay OTAA with join message from EEPROM.
eeprom_read(otaa->eeprom_addr, data, 32);
lorariot_replay_otaa(data);
lorariot_replay_otaa(otaa->appkey, data);
// TODO: read frame counter from EEPROM.
}
......@@ -58,12 +57,16 @@ void pvd_otaa_reset(provider_t *pvd)
uint8_t *data = loraraiot_retrieve_otaa();
eeprom_write(otaa->eeprom_addr, data, 32);
// TODO: save frame counter.
// Resend the join message to port 6.
// Resend the join message to port 10.
lorariot_mcps_t mcps = LORARIOT_CONFIRMED(DR_0);
mcps.buffer = data;
mcps.len = 32;
mcps.port = 10;
lorariot_send(&mcps);
// Wait the message to be fully sent.
lorariot_waitsend();
}
......@@ -42,8 +42,8 @@ provider_t pvd_orange_cmd = PVD_IMPLEM_OTAA(orange_cmd_otta);
// All defined providers.
static provider_t *pvd_all[] = {
&pvd_orange_bm,
// &pvd_orange_cmd
//&pvd_orange_bm,
&pvd_orange_cmd
};
// Number of defined providers.
......
......@@ -13,7 +13,7 @@ This project is under the MIT license
// Current loaded provider.
static provider_t *current_pvd;
static provider_t *current_pvd = NULL;
// Mutex on sending.
static mutex_t send_mutex = MUTEX_INIT;
......
......@@ -14,6 +14,8 @@ This project is under the MIT license
#define ORANGE_BM_APPKEY { 0x4B, 0x20, 0xEF, 0x23, 0xB1, 0xC3, 0xA9, 0x39, 0x3F, 0x03, 0x4F, 0x65, 0x27, 0xCA, 0x71, 0xF2 }
// Orange provider for command.
#define ORANGE_CMD_DEVEUI { 0x18, 0xC0, 0x81, 0xB5, 0x70, 0x9C, 0x54, 0x55 }
#define ORANGE_CMD_APPEUI { 0x90, 0x5C, 0x55, 0x55, 0xC7, 0xCD, 0x88, 0xBE }
#define ORANGE_CMD_APPKEY { 0x30, 0xB8, 0xDC, 0x3A, 0xDF, 0x36, 0x30, 0x38, 0x07, 0xD0, 0x3F, 0x02, 0x23, 0x03, 0xB0, 0x3A }
// #define ORANGE_CMD_DEVEUI { 0x18, 0xC0, 0x81, 0xB5, 0x70, 0x9C, 0x54, 0x55 }
// #define ORANGE_CMD_APPEUI { 0x90, 0x5C, 0x55, 0x55, 0xC7, 0xCD, 0x88, 0xBE }
#define ORANGE_CMD_DEVEUI { 0x19, 0xC0, 0x81, 0xB5, 0x70, 0x9C, 0x54, 0x55 }
#define ORANGE_CMD_APPEUI { 0x91, 0x5C, 0x55, 0x55, 0xC7, 0xCD, 0x88, 0xBE }
#define ORANGE_CMD_APPKEY { 0x08, 0xAC, 0xA9, 0x4C, 0xA5, 0xFD, 0x3E, 0xF1, 0x11, 0x9D, 0x7B, 0x73, 0x5E, 0xE7, 0x3D, 0x5A }
......@@ -11,6 +11,8 @@ LGPLv2.1 license.
#include "controller.h"
#include "LoRaMac-extra.h"
#include <string.h>
// Make OTAA join request in LoRaRIOT thread.
static void _otaa(lorariot_otaa_t *otaa)
......@@ -60,10 +62,11 @@ uint8_t *loraraiot_retrieve_otaa(void)
// Replay OTAA with previous join data.
void lorariot_replay_otaa(uint8_t *data)
void lorariot_replay_otaa(uint8_t *appkey, uint8_t *data)
{
uint8_t size = data[0];
LoRaMacDevNonce = (data[30] << 8) | (data[29]);
LoRaMacDevNonce = (data[30] << 8) | data[29];
LoRaMacAppKey = appkey;
LoRaMacApplyJoin(data + 1, size);
}
......@@ -87,6 +87,15 @@ void *lorariot_event_loop(void *arg)
msg_reply(&msg, &msg_resp);
} break;
case LORARIOT_TYPE_LORAMAC_TX_STATUS:
case LORARIOT_TYPE_LORAMAC_JOIN: {
msg_t msg_ret;
msg_ret.type = msg.type;
msg_ret.content.value = msg.content.value;
msg_send(&msg_ret, lorariot.caller_pid);
break;
}
case LORARIOT_TYPE_LORAMAC_LINK_CHECK: {
// MlmeConfirm_t *confirm = (MlmeConfirm_t *)msg.content.ptr;
// mac->link_chk.demod_margin = confirm->DemodMargin;
......
......@@ -116,7 +116,7 @@ void lorariot_mcps_indication(McpsIndication_t *indication)
msg_t msg;
msg.type = LORARIOT_TYPE_LORAMAC_TX_STATUS;
msg.content.value = LORARIOT_TX_DONE;
msg_send(&msg, lorariot.caller_pid);
msg_send(&msg, lorariot_pid);
}
......
......@@ -22,10 +22,12 @@ void lorariot_mcps_confirm(McpsConfirm_t *confirm)
if (confirm->Status != LORAMAC_EVENT_INFO_STATUS_OK)
msg.content.value = LORARIOT_TX_CNF_FAILED;
else if (confirm->McpsRequest != MCPS_UNCONFIRMED)
return; // For confirmed requests, we use indication event.
else
msg.content.value = LORARIOT_TX_DONE;
msg_send(&msg, lorariot.caller_pid);
msg_send(&msg, lorariot_pid);
}
......@@ -40,12 +42,12 @@ void lorariot_mlme_confirm(MlmeConfirm_t *confirm)
msg_t msg;
msg.type = LORARIOT_TYPE_LORAMAC_JOIN;
msg.content.value = confirm->Status;
msg_send(&msg, lorariot.caller_pid);
msg_send(&msg, lorariot_pid);
} break;
case MLME_LINK_CHECK: {
if (confirm->Status == LORAMAC_EVENT_INFO_STATUS_OK) {
DEBUG("[semtech-loramac] link check received\n");
DEBUG("[lorariot] link check received\n");
msg_t msg;
msg.type = LORARIOT_TYPE_LORAMAC_LINK_CHECK;
msg.content.ptr = confirm;
......@@ -63,6 +65,7 @@ void lorariot_mlme_confirm(MlmeConfirm_t *confirm)
// Send an MCPS frame in LoRaRIOT thread.
static void _send_mcps(lorariot_mcps_t *mcps)
{
DEBUG("[lorariot] making MCPS request\n");
McpsReq_t req;
// Change custom parameters of IMAG region.
......@@ -87,9 +90,11 @@ static void _send_mcps(lorariot_mcps_t *mcps)
lorariot_debug_status("MCPS request", status);
// Get uplink frame counter (for storing it in EEPROM).
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_UPLINK_COUNTER;
LoRaMacMibGetRequestConfirm(&mibReq);
// MibRequestConfirm_t mibReq;
// mibReq.Type = MIB_UPLINK_COUNTER;
// LoRaMacMibGetRequestConfirm(&mibReq);
// Save it to lorariot object.
// Now notify the caller thread that we made the request.
msg_t msg;
......@@ -100,24 +105,28 @@ static void _send_mcps(lorariot_mcps_t *mcps)
// Send some data using MCPS interface.
void lorariot_send(lorariot_mcps_t *mcps)
int lorariot_send(lorariot_mcps_t *mcps)
{
// Call `LoRaMacMcpsRequest` in event loop thread.
lorariot_call((lorariot_func_t)_send_mcps, mcps);
DEBUG("[lorariot] MCPS call requested!\n");
// Wait for TX status information from LoRaMAC-node.
msg_t msg;
msg_receive(&msg);
// TODO: return status code.
DEBUG("[lorariot] MCPS requested!\n");
return msg.content.value;
}
// Wait for "confirm" / "indication" event.
void lorariot_waitsend(void)
int lorariot_waitsend(void)
{
lorariot.caller_pid = thread_getpid();
DEBUG("[lorariot] Wait for confirm!\n");
msg_t msg;
msg_receive(&msg);
return msg.content.value;
}
......@@ -138,9 +138,10 @@ uint8_t *loraraiot_retrieve_otaa(void);
/**
* @brief Replay OTAA with previous join data.
* @param appkey Application key used during the OTAA.
* @param data Data of the last join response.
*/
void lorariot_replay_otaa(uint8_t *data);
void lorariot_replay_otaa(uint8_t *appkey, uint8_t *data);
/**
......@@ -160,10 +161,12 @@ void lorariot_call(lorariot_func_t func, void *arg);
/**
* @brief Send some data using MCPS interface.
* @param mcps MCPS information (data, DR, ...).
* @return Status of the MCPS request (@see LoRaMacStatus_t).
*/
void lorariot_send(lorariot_mcps_t *mcps);
int lorariot_send(lorariot_mcps_t *mcps);
/**
* @brief Wait for "confirm" / "indication" event.
* @return Status of the transmission (@see LORARIOT_* codes).
*/
void lorariot_waitsend(void);
int lorariot_waitsend(void);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment