Online LoRaWAN packet decoder


(Arjan) #1

To make (referring to) debugging a bit easer for those who do not have Node.js installed, I’ve set up a RunKit Endpoint for the nice:

See https://runkit.io/avbentem/lorawan-packet-decoder/branches/master and, e.g., https://runkit.io/avbentem/lorawan-packet-decoder/branches/master?data=ADFGUkFEshgAdAoAAACyGADXQ5rzpZs=


Decrypt LoRaWan packet in C++
(Kyosuke Yoshizu) #2

Hi,
I registered to the thing netwok
and NWKSKEY,APPSKEY,DEVADDR is defined next value.

NWKSKEY[16] = 99D58493D1205B43EFF938F0F66C339E
APPSKEY[16] = 0A501524F8EA5FCBF9BDB5AD7D126F75
DEVADDR = 260413AE;

LoRa Gate way server was transfered next encrypt data
QK4TBCaAAAABb4ldmIEHFOMmgpU=

Can I decrypt this data message?

Best regards,
yoshizu


(Arjan) #3

The online version does did not check or decrypt anything (right now). So, you’ll need to use the library yourself. Note that the DevAddr is in the non-encrypted part of the message headers.

mkdir my-decoder-test
cd my-decoder-test
npm install lora-packet

node <<END
const lorapacket = require('lora-packet');
const nwkSKey = new Buffer('99D58493D1205B43EFF938F0F66C339E', 'hex');
const appSKey = new Buffer('0A501524F8EA5FCBF9BDB5AD7D126F75', 'hex');
const data = new Buffer('QK4TBCaAAAABb4ldmIEHFOMmgpU=', 'base64');

const packet = lorapacket.fromWire(data);
console.log(packet.toString());

// When the node's counter has exceeded 65,536, then use a recent FCnt value
// to supply its MSB in the call to verifyMIC:
//    const recentFCnt = 476604;
//    const msb = new Buffer(2);
//    msb.writeUInt16LE(recentFCnt >> 16, 0);
//    const valid = lorapacket.verifyMIC(packet, nwkSKey, null, msb);
const valid = lorapacket.verifyMIC(packet, nwkSKey);
console.log('MIC: ' + (valid ? 'OK' : 'FAIL'));

const payload = lorapacket.decrypt(packet, appSKey, nwkSKey);
// Assume plain ASCII text, which is bad, but works for your example...
console.log('Payload: ' + payload.toString());
END

…gives you:

Message Type = Data
            PHYPayload = 40AE130426800000016F895D98810714E3268295

          ( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
                  MHDR = 40
            MACPayload = AE130426800000016F895D98810714
                   MIC = E3268295

          ( MACPayload = FHDR | FPort | FRMPayload )
                  FHDR = AE130426800000
                 FPort = 01
            FRMPayload = 6F895D98810714

                ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
               DevAddr = 260413AE (Big Endian)
                 FCtrl = 80
                  FCnt = 0000 (Big Endian)
                 FOpts = 

          Message Type = Unconfirmed Data Up
             Direction = up
                  FCnt = 0
             FCtrl.ACK = false
             FCtrl.ADR = true
MIC: OK
Payload: abcdefg

(You should keep the session keys secret, as anyone can now send data to your application. Also, you should not send text.)


Payload Decryption
(Kyosuke Yoshizu) #4

Dear arjanvanb

Thank you for all your help.
Your answer is what I was exactly requiring.
This is great!

Best regards,
yoshizu


(Sagu25patel) #6

Hello,

Anyone have LoRaWAN 1.1.x version packet decoder?

Please help me…!