anthonykirby / lora-packet

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

Command Line frame decoding ... #126

Closed kjo-sdds closed 5 months ago

kjo-sdds commented 5 months ago

Hello!

I've got the following : lora-packet-decode --appkey 176C3C601A5FEE50F26FA6D1D193D611 --nwkkey 4A43B74FE531126056CDE739EC05C92B --base64 QNmZCyYAMFwFAVh1pho=

Which yields :

decoding from Base64:  QNmZCyYAMFwFAVh1pho=
Decoded packet
--------------
Message Type = Data
            PHYPayload = 40D9990B2600305C05015875A61A

          ( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
                  MHDR = 40
            MACPayload = D9990B2600305C0501
                   MIC = 5875A61A (BAD != CF0C43F5)

          ( MACPayload = FHDR | FPort | FRMPayload )
                  FHDR = D9990B2600305C
                 FPort = 05
            FRMPayload = 01
             Plaintext = CC ('.')

                ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
               DevAddr = 260B99D9 (Big Endian)
                 FCtrl = 00
                  FCnt = 5C30 (Big Endian)
                 FOpts = 

          Message Type = Unconfirmed Data Up
             Direction = up
                  FCnt = 23600
             FCtrl.ACK = false
             FCtrl.ADR = false
       FCtrl.ADRACKReq = false

But I know the key and transmission to be good. I also have checked on that website : https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh/?data=QNmZCyYAMFwFAVh1pho%3D&nwkskey=4A43B74FE531126056CDE739EC05C92B&appskey=176C3C601A5FEE50F26FA6D1D193D611 Which seems to use your tool ... but which gave me :

Assuming base64-encoded packet
QNmZCyYAMFwFAVh1pho=

Message Type = Data
  PHYPayload = 40D9990B2600305C05015875A61A

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
        MHDR = 40
  MACPayload = D9990B2600305C0501
         MIC = 5875A61A (from packet)
             = 5875A61A (expected, assuming 32 bits frame counter with MSB 0001)

( MACPayload = FHDR | FPort | FRMPayload )
        FHDR = D9990B2600305C
       FPort = 05
  FRMPayload = 01 (from packet, encrypted)
             = CC (decrypted)

      ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
     DevAddr = 260B99D9 (Big Endian)
       FCtrl = 00
        FCnt = 5C30 (Big Endian)
       FOpts = 

Message Type = Unconfirmed Data Up
   Direction = up
        FCnt = 23600 (from packet, 16 bits) 
             = 89136 (32 bits, assuming MSB 0x0001)
   FCtrl.ACK = false
   FCtrl.ADR = false

Happy to help if I can answer any question

Just did a fresh Node lts install ... and installed your tool using npm. (so should be pretty much last version)

anthonykirby commented 5 months ago

Hi, If you read the notes carefully on the runkit site, they explain that the top 16bits of FCnt aren't included in the message, and the assumption is that a client knows this. So what the site does is a brute force search of all possible values until it gets a valid MIC. If you want this feature you could implement it easily in a loop.

Anthony

(sent from my phone; please excuse typos & autocorrect)

On Mon, 25 Mar 2024, 14:32 kjo-sdds, @.***> wrote:

Hello!

I've got the following : lora-packet-decode --appkey 176C3C601A5FEE50F26FA6D1D193D611 --nwkkey 4A43B74FE531126056CDE739EC05C92B --base64 QNmZCyYAMFwFAVh1pho=

Which yields :

decoding from Base64: QNmZCyYAMFwFAVh1pho= Decoded packet

Message Type = Data PHYPayload = 40D9990B2600305C05015875A61A

      ( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
              MHDR = 40
        MACPayload = D9990B2600305C0501
               MIC = 5875A61A (BAD != CF0C43F5)

      ( MACPayload = FHDR | FPort | FRMPayload )
              FHDR = D9990B2600305C
             FPort = 05
        FRMPayload = 01
         Plaintext = CC ('.')

            ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
           DevAddr = 260B99D9 (Big Endian)
             FCtrl = 00
              FCnt = 5C30 (Big Endian)
             FOpts =

      Message Type = Unconfirmed Data Up
         Direction = up
              FCnt = 23600
         FCtrl.ACK = false
         FCtrl.ADR = false
   FCtrl.ADRACKReq = false

But I know the key and transmission to be good. I also have checked on that website :

https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh/?data=QNmZCyYAMFwFAVh1pho%3D&nwkskey=4A43B74FE531126056CDE739EC05C92B&appskey=176C3C601A5FEE50F26FA6D1D193D611 Which seems to use your tool ... but which gave me :

Assuming base64-encoded packet QNmZCyYAMFwFAVh1pho=

Message Type = Data PHYPayload = 40D9990B2600305C05015875A61A

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] ) MHDR = 40 MACPayload = D9990B2600305C0501 MIC = 5875A61A (from packet) = 5875A61A (expected, assuming 32 bits frame counter with MSB 0001)

( MACPayload = FHDR | FPort | FRMPayload ) FHDR = D9990B2600305C FPort = 05 FRMPayload = 01 (from packet, encrypted) = CC (decrypted)

  ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
 DevAddr = 260B99D9 (Big Endian)
   FCtrl = 00
    FCnt = 5C30 (Big Endian)
   FOpts =

Message Type = Unconfirmed Data Up Direction = up FCnt = 23600 (from packet, 16 bits) = 89136 (32 bits, assuming MSB 0x0001) FCtrl.ACK = false FCtrl.ADR = false

Happy to help if I can answer any question

Just did a fresh Node lts install ... and installed your tool using npm. (so should be pretty much last version)

— Reply to this email directly, view it on GitHub https://github.com/anthonykirby/lora-packet/issues/126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKVFHKNTBOEYXVPCULRALDY2AYRVAVCNFSM6AAAAABFHEAAEWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIYDKOJQGUYDAOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kjo-sdds commented 5 months ago

Ohh sorry! I didn't notice it was due to the frame counter ... I stopped the comparison a little too early in the reading ... Thanks for the heads up ... and your great work !!