anthonykirby / lora-packet

LoRa radio packet decoder
MIT License
261 stars 83 forks source link

Lora packet Decoding #7

Closed codecandy2015 closed 7 years ago

codecandy2015 commented 7 years ago

Hi Anthony, I find your work on LoRa packet decoding quite intersting. I am currently exploring LoRAWAN with TTN. I have hard time decoding these payloads.

My data is: 7B226D656173757265496473223A5B315D2C2276616C756573223A5B32325D2C2270726F66696C654964223A313030327D

to me this looks like a HEX string.

I am following the same example you have provided in this GitHUB. How ever when I use the nwSKey and AppSKey, I am not able to see my payload decoded.

The MIC check fails. Is there a way to cross check the decoding process ? any help is appreciated Dom

anthonykirby commented 7 years ago

You're correct that this looks like hex - did you try a hex decoder? :-)

The lora-packet library is aimed at users who have the raw "wire-level" data, like you'd see going through a gateway. Your example is the decoded data from TTN, so all the LoRa decoding has happened already.

codecandy2015 commented 7 years ago

Hi Anthony,Thanks for your reply. I took this payload on the data console of the TTN. It was hex. I was able to use your web interface and got the payload which was base64 encoded. I was able to see the original message. I am trying something similar on the loriot network. I get the following payloads..

NwSKey = 12C822012DCC304E7CD161CA7F98D29C AppSKey = 80B654DBB82CC7C1D4F9E5139F327F71

JSON up: {"rxpk":[{"tmst":354089252,"chan":6,"rfch":1,"freq":903.500000,"stat":1,"modu":"LORA","datr":"SF10BW125","codr":"4/5","lsnr":14.0,"rssi":-29,"size":29,"data":"QKGfmAGAkQAClKBkJAt8EcGHPldTfy+u8mM8cDk="}]}INFO: [down] PULL_ACK received in 332 ms INFO: Received pkt from mote: 01989FA1 (fcnt=144) JSON up: {"rxpk":[{"tmst":339084708,"chan":1,"rfch":0,"freq":902.500000,"stat":1,"modu":"LORA","datr":"SF10BW125","codr":"4/5","lsnr":13.8,"rssi":-31,"size":29,"data":"QKGfmAGAkAACRZ7Vgm33Uj8TwpSOOya1hhJ/ojw="}]}INFO: [down] PULL_ACK received in 551 ms INFO: Received pkt from mote: 01989FA1 (fcnt=145) when I use the same web interface of yours for the data.. I am not able to get the right payload.Am I doing the right thing for this perhaps ? or I need to decode the data in a different way ?any advice would be appreciated. regardsDomnic

Anthony Kirby <notifications@github.com> schrieb am 12:42 Freitag, 9.Juni 2017:

Closed #7.— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

anthonykirby commented 7 years ago

Hi Dom, I'm slightly puzzled by your words "your web interface": I only wrote an npm library.

Looking at your data, the "QKGfmAGAkQAClKBkJAt8EcGHPldTfy+u8mM8cDk=" is Base64, and is probably a raw packet suitable for decoding using this library. The first byte of your data (in hex) is 0x40, which is a valid LoRa "Message Type" byte meaning "Unconfirmed Data Up".

If you haven't tried this already, I suggest copying my "demo1.js" and substituting your data (converted appropriately). If you get a MIC failure & badly decrypted data, you could retry with the endian-ness of your keys reversed - I've written a bit about endianness in the README.

thanks Anthony

codecandy2015 commented 7 years ago

Hi Anthony,Yes I had a look at the demo code and I did try it out. This is the output I get.

C:\dev\nodejs\Workspace\PoCs\ken-lora-decoder>npm start
> ken-lora-decoder@0.0.1 start C:\dev\nodejs\Workspace\PoCs\ken-lora-decoder> node app.js
packet.toString()=Message 
Type = Data  
PHYPayload = 40A19F98018091000294A064240B7C11C1873E57537F2FAEF2633C7039
( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )        
MHDR = 40  
MACPayload = A19F98018091000294A064240B7C11C1873E57537F2FAEF2         
MIC = 633C7039
( MACPayload = FHDR | FPort | FRMPayload )        

FHDR = A19F9801809100      
 FPort = 02 
 FRMPayload = 94A064240B7C11C1873E57537F2FAEF2
      ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )     

DevAddr = 01989FA1 (Big Endian)      
FCtrl = 80        
FCnt = 0091 (Big Endian)      
FOpts = Message Type = Unconfirmed Data Up   
Direction = up       
FCnt = 145   
FCtrl.ACK = false   
FCtrl.ADR = true
packet 
MIC=633c7039
FRMPayload=94a064240b7c11c1873e57537f2faef2
MIC check=OK
calculated MIC=633c7039
Decrypted='       �.ʋ��@�p'
============ Finishing Decoding LoRA packet

There you see MIC is OK. but that there is something fishy with the the Decrypted text ? CheersDom

anthonykirby commented 7 years ago

Hi Dom, is it possible that your data is binary? In that case, you'd expect garbage from "toString" Ant

codecandy2015 commented 7 years ago

Hi Anthony, I tried to do lora_packet.decrypt(packet, AppSKey, NwkSKey).toString('hex')

I do get a HEX string like this 00000000000000fe2eca8bacaa40a670

But I tried to convert this to base64 also to Ascii but none of these convertions get me anywhere. I am not sure if it was sent as Binary.. as I just get the payload as a JSON file. if it is a Binary data.. how coud I get it back as ASCII text ? do you have any recommendations perhaps ? regards Dom

anthonykirby commented 7 years ago

Hi Dom, that's great, so the decryption worked! (Failed decryption will look like random, not containing strings of zeros).

However, you'll need to investigate the binary format of your data yourself: I can't do this for you.

Anthony

avbentem commented 7 years ago

@anthonykirby

I'm slightly puzzled by your words "your web interface": I only wrote an npm library.

As an aside, that might be my https://runkit.com/avbentem/lorawan-packet-decoder which has a frontend available at https://runkit.io/avbentem/lorawan-packet-decoder/branches/master